Languages
[Edit]
EN

Git squash last 2 commits into 1 commit

1 points
Created by:
Mohammad-Oneal
327

Quick solution:

 

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

 

Example

Edit

First command:

Change pick to squash:

 

Change time of last commit to current time

Edit

See more: Git squash - change time of last commit to current time

 

Git bash / vim - replace replace pick with squash

Edit

Above command will replace pick with squash from 2nd to 17th line (commit).

If we have 5 commits to squash then:

TODO: find pick only at the beginning of the line.

 

See also:

Edit
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Git - rebase & squash

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join