Squash Commits of a branch after merging in GIT

Viewed 2487

Hi I have a branch stable which contains merged commits of other branches. The structure is as follows:

Commit History:

Commit 1 - Branch 1 commit 1 ------------- Hash Code 1
Commit 2 - Branch 2 commit 1 ------------- Hash Code 2
Commit 3 - Branch 2 commit 2 ------------- Hash Code 3
Commit 4 - Branch 2 commit 3 ------------- Hash Code 4
Commit 5 - Branch 3 commit 1 ------------- Hash Code 5

Branch 1,2,3 are deleted and has been merges with stable. Is there any way that in the commit history I can squash Commit 3 and Commit 4.

The desired result:

Commit 1 - Branch 1 commit 1 ------------- Hash Code 1
Commit 2 - Branch 2 commit 1 ------------- Hash Code 2
Commit 5 - Branch 3 commit 1 ------------- Hash Code 5

When I do git rebase -i, it gives the noop scrren in rebasing.enter image description here

1 Answers

You can do git rebase -i to perform an interactive rebase.

git rebase -i HEAD~4

change

pick  commit 1
pick  commit 2
pick  commit 3
pick  commit 1

into this

pick  commit 1
s     commit 2
s     commit 3
pick  commit 1

save changes and do git push -f

Related