tsadkan yitbarek
tsadkan yitbarek

Reputation: 1370

git combine two consecutive commits

I have the following commits in my branch.

  1. last commit
  2. third commit
  3. second commit
  4. first commit

How could I combine commit 3 and 2 but with commit message of commit 2. This is the result I will be expecting

  1. last commit
  2. second commit (3 is combined to 2)
  3. first commit

Upvotes: 2

Views: 939

Answers (2)

emremrah
emremrah

Reputation: 1765

  • git rebase -i <sha key of first commit>
  • An editor will be opened. Change pick to squash at second and third commit
  • Write and quit
  • The editor will pop up again for you to write the new commit message.

Upvotes: 1

Chris Maes
Chris Maes

Reputation: 37742

you can do this interactively using

git rebase -i HEAD~4

then you will see an editor like

pick <sha-1> commit 1
pick <sha-2> commit 2
pick <sha-3> commit 3
pick <sha-4> commit 4

which you need to change to:

pick <sha-1> commit 1
pick <sha-2> commit 2
fixup <sha-3> commit 3
pick <sha-4> commit 4

save and quit, and that's it.

Upvotes: 7

Related Questions