KatPadi's Point

Git: Squash Commits

With git it’s possible to squash previous commits into one before sharing them with others.

Step 1

For example you want to squash your last 3 commits:

git rebase -i HEAD~3

On the other hand, if you want to just simply squash all the unpushed commits:

git rebase -i origin/master

If you have many commits and want to start from a certain commit:

git rebase -i

Any of the command above will prompt open your editor with something like:

pick a92f09 Added new feature X
pick ca9f90a Some other stuff I did
pick d18a6h1 More stuff I did

This will show up in your editor:

pick a92f09 Added new feature X
squash ca9f90a Some other stuff I did
squash d18a6h1 More stuff I did

Note: If you don’t have an editor defined in your config, you will encounter Could not execute editor. Just do git config --global core.editor /usr/bin/vim for you to be able to proceed.

Step 2

Next, we can configure git on what to do with the commits. Let’s say, I want to keep commit a92f09. Git squash-ing the following two commits into the first one will leave us with one single commit with all the commits in it. To do that, change your file to this:

pick a92f09 Added new feature X
squash ca9f90a Some other stuff I did
squash d18a6h1 More stuff I did

Save and exit.

That’s it. Git squash is especially useful if you want to wrap up “all in a day’s work” or if you want to have a clean and concise git history.

TL;DR

Use git rebase -i origin/master and replace “pick” on the second and succeeding commits with “squash”.

git squash?

17 comments for “Git: Squash Commits

  1. March 2, 2017 at 1:26 pm

    Since we re combining so many commits, Git allows you to modify the new commit s message based on the rest of the commits involved in the process. Edit the message as you see fit, then save and quit. Once that s done, your commits have been successfully squashed!

  2. March 9, 2017 at 3:49 am

    And obviously I was squashing the last five commits on branch foo, but you could change that however you like.

  3. Doratisee
    April 6, 2017 at 4:27 am

    hi!

  4. Psync
    June 2, 2020 at 9:56 am

    I really cannot add more to what was said because you have disclosed all important information. I must say that this site is quite nice.
    In this website there is also a lot of interesting and useful information:

    [url=https://dribbble.com/Shul/about]נערות ליווי[/url]

  5. Psync
    June 30, 2020 at 4:57 am

    I really cannot add more to what was said because you have disclosed all important information. I must say that this site is quite nice.
    In this website there is also a lot of interesting and useful information:

    [url=http://escortgirls.sites.livecms.co.il/]interesting page[/url]

  6. Psync
    August 12, 2020 at 10:34 am

    I have read somewhere similar point of view and I totally agree with what you said. However, there are also some other things could be mentioned on this topic, but overall I like what you described.
    In this website there is also a lot of interesting and useful information:

    [url=http://www.tapuz.co.il/blogs/viewentry/7527718]נערות ליווי נוצצות[/url]

  7. January 4, 2021 at 4:04 pm

    Nice website and I like to follow everythoinh here. I always share everything here with my friends.
    This site I like too:

    [url=https://freesexdb.com/]סרטים כחולים[/url]

  8. February 14, 2021 at 9:07 am

    This is my first time go to see at here and i am genuinely impressed to read all at alone place. Orelia Earvin Rolph

  9. February 17, 2021 at 12:39 am

    Everything is very open with a precise clarification of the challenges. It was really informative. Your site is very helpful. Thank you for sharing! Linnet Abie Bullough

  10. Kic
    April 30, 2021 at 11:04 am

    What can be better than this wonderful website and a cup of coffee in the evening!

    [url=http://elijah32086.onesmablog.com/Tips-to-Find-a-Very-good-Escort-Agency-36626644]דירות דיסקרטיות בחיפה[/url]

  11. dob
    May 21, 2021 at 9:17 pm

    Miss such qualitetive information.

    [url=https://old.reddit.com/r/news/comments/jggp9w/%D7%97%D7%A9%D7%A4%D7%A0%D7%99%D7%95%D7%AA_%D7%91%D7%A6%D7%A4%D7%95%D7%9F/]חשפניות בצפון[/url]

  12. dob
    June 15, 2021 at 6:58 pm

    Good website and I even like comments here.

    [url=https://pixelation.org/index.php?action=profile;area=summary;u=210558]חשפניות בצפון[/url]

  13. Psync
    September 12, 2021 at 11:03 am

    I really cannot add more to what was said because you have disclosed all important information. I must say that this site is quite nice.
    In this website there is also a lot of interesting and useful information:

    [url=http://www.tapuz.co.il/blogs/viewentry/7527718]נערות ליווי נוצצות[/url]

  14. Adads
    September 13, 2021 at 9:40 am

    Please keep writing such nice things.

    [url=https://rentacarnovisad.shutterfly.com/]דירות דיסקרטיות בבאר שבע[/url]

  15. skype
    September 22, 2021 at 2:08 am

    At last someone wrote something very important about such hot topic and it is very relevant nowadays.

    [url=https://loveacademy.co.il/עיסוי-מפנק-לגברים/]נערות ליווי[/url]

  16. pem
    October 8, 2021 at 2:00 am

    Great writings here are always and I really I like everything here.
    I this like as well:

    [url=https://www.sbnation.com/users/frank4865]נערות ליווי בבת ים[/url]

  17. Emets
    October 10, 2021 at 5:08 am

    I wish I could have the same website. Anyway, I always share with my friends whatever I read here.

    [url=https://www.sportsadvantage.com/blog/post/index/id/64/?___SID=U]שיחות סקס[/url]

Leave a Reply to Adads Cancel reply

Your email address will not be published. Required fields are marked *