EN
Git squash last 2 commits into 1 commit
1 points
Quick solution:
xxxxxxxxxx
1
git rebase -i HEAD~2
Flow:
git rebase --interactive HEAD~2
- change first word of second line from "pick" to "squash"
:wq
(git bash write and quit)- 2 commit messages will show up
- usually we remove second message and leave only first message or we change first message
- push our local branch to remote with force -
git push -f
First command:
xxxxxxxxxx
1
$ git rebase -i HEAD~2
2
3
pick 7357fca Commit 1
4
pick fc8bc9b Commit 2
Change pick to squash:
xxxxxxxxxx
1
$ git rebase -i HEAD~2
2
3
pick 7357fca Commit 1
4
squash fc8bc9b Commit 2
xxxxxxxxxx
1
git commit --amend --date="now"
See more: Git squash - change time of last commit to current time
xxxxxxxxxx
1
2,17s/pick/squash/g
Above command will replace pick with squash from 2nd to 17th line (commit).
If we have 5 commits to squash then:
xxxxxxxxxx
1
2,5s/pick/squash/g
TODO: find pick only at the beginning of the line.