LoginSignup
13
10

More than 5 years have passed since last update.

git rebase --interactive で誰がauthorになるか問題

Last updated at Posted at 2018-04-14

wataash/git-test-squash の和訳です。

結論:Squashed commitsの最初のコミットのauthorになる。

この ように、コミットA・B・C・Dがあったとします。これらをコミットAにsquashすると、コミットAのauthorである Alan Adleman がsquashされたコミットのauthorになります。

git rebase -i HEAD~4 [注1]:

pick 10d7eee commit A
pick 88e7a36 commit B
pick 5d54325 commit C
pick 6e374dc commit D

B・C・DをAにsquashしてやります:

pick 10d7eee commit A
fixup 88e7a36 commit B
fixup 5d54325 commit C
fixup 6e374dc commit D

結果は こう なります。git show squash-into-a:

commit 8e61e787fed78bdab3abd47527f3c65d363f1ff0 (origin/squash-into-a, squash-into-a)
Author: Alan Adleman <alan@example.com>
Date:   Sat Apr 14 12:34:47 2018 +0900

    commit A

ここでは squash の代わりに fixup としましたが、結果に変わりありません。

ではDのauthorである Donald Dijkstra をauthorにしたい場合どうすれば良いでしょう?答えは簡単で、Dを最初のコミットにして、B・C・Dをsuquashするだけです:

pick 6e374dc commit D
fixup 10d7eee commit A
fixup 88e7a36 commit B
fixup 5d54325 commit C

結果は こう なります。git show squash-into-d:

commit 6116c585cfba2a9599b5dc0a11aaf27d24bae7fe (origin/squash-into-d, squash-into-d)
Author: Donald Dijkstra <donald@example.com>
Date:   Sat Apr 14 12:55:11 2018 +0900

    commit D

並び替えの際にcommit Dが他のコミットとコンフリクトする場合は、並び替えせずにcommit Aにsquashした後、git commit --author='Donald Dijkstra <donald@example.com>' --amend --no-edit でauthorを書き換えれば良いでしょう。Authorのtypoが怖ければ git commit --author=$(git log '--format=%an <%ae>' -1 6e374dc) --amend --no-edit で。

注1: ~4 は「4つ親のコミット」を表します。コミットログ を見れば分かるように、commit Dの4つ親は init、79e9533 です。HEAD~~~~ としても良いです。詳しくは git-rev-parse(1) を見て下さい。

See also

13
10
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
13
10