1
votes

I have a test repository with the following history:

commit eb4a4d52a8fe6abdebb93c7747beac2d511003af (HEAD, master) Merge: 22f849c 94e27d1 Author: Your Name Date: Mon Jan 27 00:51:42 2014 +0100

Merge branch 'cheryr'

Conflicts:
    FILE

commit 22f849c403b6cdf43280e66e937931bf9d0ab25a Author: Your Name Date: Sun Jan 26 21:01:35 2014 +0100

4

toto

commit 94e27d1c78833784619e25eeb8e0186f154f2282 (cheryr) Author: Your Name Date: Mon Jan 27 00:48:12 2014 +0100

toto

commit 2368d78ba95811e9eb9897487cccb7b7f6927910 Author: Your Name Date: Sun Jan 26 22:31:51 2014 +0100

10

commit b1f0f8a1a1951e661a7e833314fc483085516b0c (tmp) Author: Your Name Date: Sun Jan 26 22:19:56 2014 +0100

9

commit 3a8f2e17e721821ae8ebd1e272437c8632224b9a Author: Your Name Date: Sun Jan 26 22:18:23 2014 +0100

8

commit 28d4a62d4d21c3e8155553e1216bfa981afe7212 Author: Your Name Date: Sun Jan 26 22:15:42 2014 +0100

7

Is this possibe to squash a few first commits into one, together with merge commit? It's not possible to simply pass HEAD~4 to git rebase -i because it will take 4 commits back from the first parent of the merge commit.

2

2 Answers

1
votes

git rebase -i HEAD~4 would work just fine, also if it's a far commit or you don't know how far it is, take the hash of the parent of the first commit you want to edit, or for me I take the hash and append a ^ for saying parent

git rebase -i hash^

I think ~ would work too

git rebase -i hash~

Then you can set the first commit as pick p or reword if you want to change it's message r and the remaining 3 as fixup f so it doesn't keep stopping asking you for a new commit message, it will stop in the middle for any conflicts, also expect that you will need to re-resolve any conflicts if you pass by a commit that created one.

0
votes

try: git rebase -i HEAD^2~3

'^' sign is used to select 1 of the parents (in this case ^2 means select second parent, and then ~3 means 'go 3 commits back')