1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

masterブランチにコミット済みの内容をレビューしたときにやったこと

Last updated at Posted at 2021-03-07

状況

プログラミングを始めたばかりの友人にコードレビューをお願いされた。
ソースコードはGithubにあって、masterブランチにすべてコミットされている。
行単位のコメントを付けたいが、どうしたら良いか。

対応方針

masterブランチとは切り離されたブランチを二つ作成し、GitHubでプルリクエストを作成する。
そこでレビューを行う。

やったこと

# 対象のリポジトリをクローンする
git clone ...

# 親を持たないブランチを作成する
git checkout --orphan  tmp_branch_for_review

# 空の状態のブランチを作りたいのでいったん全部消す(ここら辺、もっとスマートなやり方がありそう)
git rm --cached . -r

# ファイルが無いとコミットでエラーになるのでREADMEだけ戻す。(commit時のオプションで回避できそう)
git add README.md

# commitしてpush。このブランチがプルリクエストのだし先となる。
git commit -m 'Initial Commit'
git push origin tmp_branch_for_review


# プルリクエストの出し元となるブランチを作成する
git checkout -b tmp_branch_for_review2

# 先ほどgit rmで削除したファイルを戻す
git add .

# commitしてpush
git commit -m 'commit'
git push origin tmp_branch_for_review2

"tmp_branch_for_review2"から"tmp_branch_for_review"にプルリクエストを作成する。

補足

masterブランチの最初のコミットが単純な内容であれば、もっと単純な方法が取れたと思う。例えば、masterブランチの最初のコミットからブランチを切り、そこに対してmasterブランチからプルリクエストを出せば良さそう。

今回は、masterブランチの最初のコミットでほぼ全てのファイルが追加されていたため、色々うまくいかずに今回の方法を取った。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?