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?

60 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. December 24, 2021 at 5:56 am

    We are a group of volunteers and opening a new scheme in our community. Your web site offered us with valuable information to work on. You’ve done an impressive job and our entire community will be thankful to you.

  5. Beice
    December 24, 2021 at 9:08 am

    Great idea to write about such stuff here. I am grateful for every word.
    [url=https://ilxxxindex.simplesite.com/450916574]נערות ליווי בתל אביב[/url]

  6. pem
    December 29, 2021 at 6:02 pm

    Nothing to add, just I love to spend time in this website and read every word here.
    I this like as well:

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

  7. pem
    January 23, 2022 at 5:01 am

    Nothing to add, just I love to spend time in this website and read every word here.
    I this like as well:

    [url=http://onlineboxing.net/jforum/user/profile/66500.page]נערות ליווי ברמת גן[/url]

  8. skype
    February 3, 2022 at 11:04 pm

    I cannot thank you enough for such great writing and all people to their up to the point reviews.

    [url=https://www.google.ad/url?q=https://escortlila.com/]נערות ליווי[/url]

  9. Beice
    February 9, 2022 at 6:51 am

    So nicely mentioned and looks like really professional people are writing on this website.

    [url=https://israelescort.escortbook.com/blog—-18388]נערות ליווי בישראל[/url]

  10. lber
    February 10, 2022 at 6:17 pm

    Maybe it is one of the best websites I have ever visited.

    [url=https://delhi.instructure.com/courses/124/pages/steps-to-look-for-a-sensible-escort-service]נערות ליווי בתל אביב[/url]

  11. Adads
    February 11, 2022 at 10:40 am

    What a nice website, cannot wait to read new articles.

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

  12. Emets
    February 14, 2022 at 12:07 pm

    Great place to spend time especially now. I love to this type of writing and I like comments too.

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

  13. pem
    February 23, 2022 at 8:02 pm

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

    [url=https://my.desktopnexus.com/frank4865/]נערות ליווי בבת ים[/url]

  14. skype
    February 27, 2022 at 1:24 pm

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

    [url=https://sexvsadult.info/מסיבת-רווקים-האפשרות-הבנאלית-היא-הטוב/]נערות ליווי בתל אביב[/url]

  15. skype
    March 12, 2022 at 3:52 pm

    Maybe one day I will write a book based on this perfect writing. Great job really.

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

  16. lber
    March 21, 2022 at 11:25 pm

    What a nice place to share thoughts but the most important that thoughts are positive and realistic.

    [url=https://postheaven.net/barberflat7/first-class-escorts-reveal-just-what-their-clients-want]נערות ליווי בתל אביב[/url]

  17. skype
    May 13, 2022 at 11:03 pm

    Maybe one day I will write a book based on this perfect writing. Great job really.

    [url=https://sexvsadult.info/הפעם-הראשונה-שלי/]נערות ליווי בתל אביב[/url]

  18. May 28, 2022 at 4:15 pm

    סקס
    [url=”http://www.punterlinks.com/escort/rilli/”]http://www.punterlinks.com/escort/rilli/[/url]

  19. June 9, 2022 at 8:55 am

    סקס
    [url=”https://www.adult-works.com/escorts-tel-aviv/essie-mccarthy-mixed-533104.html”]https://www.adult-works.com/escorts-tel-aviv/essie-mccarthy-mixed-533104.html[/url]

  20. Pingback: 3lebanon
  21. Pingback: 3preservation
  22. October 21, 2022 at 3:29 am

    Hey! Quick question that’s entirely off topic. Do you know how to make your site mobile
    friendly? My web site looks weird when browsing from my iphone4.
    I’m trying to find a theme or plugin that might be able
    to resolve this issue. If you have any suggestions, please share.
    With thanks!

  23. November 18, 2022 at 7:02 am

    [url=http://etrazodone.com/]trazodone 100mg australia[/url]

  24. December 4, 2022 at 7:49 pm

    [url=http://wellbutrintab.online/]wellbutrin 75[/url] [url=http://tizanidine.run/]zanaflex 2mg tablet[/url] [url=http://synthroidl.online/]synthroid canadian pharmacy[/url] [url=http://buydoxycycline.life/]doxycycline minocycline[/url] [url=http://trustedtablets.coupons/]pharmacy com canada[/url]

  25. December 9, 2022 at 1:15 am

    [url=https://tetracyclinesumycin.shop/]tetracycline hci 500mg capsules[/url]

  26. December 9, 2022 at 2:24 pm

    [url=https://cleocintabs.shop/]clindamycin 0.1 price[/url] [url=https://buyanafranil.monster/]where to buy anafranil[/url]

  27. December 28, 2022 at 11:08 am

    [url=https://seroqueltab.quest/]seroquel 350 mg[/url]

  28. December 31, 2022 at 10:32 am

    [url=http://antabuse.lol/]buy antabuse canada[/url]

  29. December 31, 2022 at 9:43 pm

    [url=https://drugstore.us.org/]italian pharmacy online[/url]

  30. January 1, 2023 at 1:21 pm

    [url=http://sildenafilis.com/]cheap canadian pharmacy viagra[/url] [url=http://albendazole.lol/]albendazole coupon[/url] [url=http://synroid.com/]levothyroxine 50 mcg[/url] [url=http://tretinoin.lol/]where to buy tretinoin online[/url] [url=http://amoxicillind.online/]amoxicillin 875 mg buy online[/url]

  31. January 1, 2023 at 3:20 pm

    [url=http://amoxicillin.trade/]amoxil 875 medication[/url]

  32. January 1, 2023 at 4:35 pm

    [url=https://lasix.gives/]generic lasix[/url]

  33. January 2, 2023 at 1:52 am

    [url=https://colchicine.trade/]can i buy colchicine from mexico[/url]

  34. January 3, 2023 at 3:14 am

    [url=https://accurane.com/]accutane medication price[/url]

  35. January 3, 2023 at 4:53 am

    [url=https://valtrex.directory/]valtrex rx coupon[/url] [url=https://baclofen.pics/]baclofen price canada[/url] [url=https://prazosin.fun/]prazosin online[/url]

  36. January 4, 2023 at 10:12 am

    [url=https://metformin.gives/]buying metformin er[/url]

  37. January 4, 2023 at 4:20 pm

    [url=https://sildenafil.foundation/]viagra otc mexico[/url]

  38. January 6, 2023 at 9:18 am

    [url=https://amoxicillinp.online/]buy amoxil online[/url]

  39. January 7, 2023 at 10:04 pm

    [url=http://retina.charity/]retin a online pharmacy india[/url]

  40. January 11, 2023 at 12:23 am

    [url=http://isotretinoin.gives/]120mg accutane[/url]

  41. January 11, 2023 at 9:20 pm

    [url=http://augmentinp.online/]amoxicillin 107[/url]

  42. January 11, 2023 at 11:57 pm

    [url=http://vviagra.online/]order viagra online without script[/url] [url=http://albendazole.directory/]medicine albendazole[/url] [url=http://acyclovir.lol/]zovirax discount[/url] [url=http://levitraz.online/]vardenafil tablets in india[/url] [url=http://augmentin.directory/]amoxicillin 2g[/url] [url=http://albuterol.lol/]albuterol tablets for sale[/url]

  43. January 13, 2023 at 9:29 pm

    [url=https://antabusev.online/]buy antabuse online safely[/url]

  44. January 14, 2023 at 5:08 pm

    [url=https://buyalbendazole.life/]generic albendazole online[/url]

  45. January 17, 2023 at 2:37 am

    [url=https://fildena.men/]fildena 100 canada[/url]

  46. January 19, 2023 at 1:26 pm

    [url=http://diflucano.com/]diflucan pills prescription[/url] [url=http://tizanidinetab.online/]how much is tizanidine 4mg[/url] [url=http://celexa.directory/]100 mg celexa[/url] [url=http://propranolol.download/]propranolol over the counter usa[/url] [url=http://acyclovir.men/]acyclovir pill[/url] [url=http://baclofen.download/]baclofen discount[/url]

  47. January 19, 2023 at 4:45 pm

    [url=http://paxild.com/]generic paroxetine price[/url]

  48. January 19, 2023 at 9:36 pm

    [url=http://motiliumtab.online/]motilium canada over the counter[/url] [url=http://tizanidinetab.online/]zanaflex generic price[/url] [url=http://paxild.com/]paxil for anxiety and depression[/url]

  49. January 22, 2023 at 10:38 pm

    [url=http://healthwarehouseonlinepharmacy.com/]canadian pharmacy world coupon[/url]

  50. January 23, 2023 at 9:40 am

    [url=https://ampicillin.lol/]ampicillin 500[/url]

  51. January 24, 2023 at 10:49 pm

    [url=http://nexium.lol/]nexium best price[/url]

  52. January 26, 2023 at 2:04 am

    [url=https://ampicillin.directory/]ampicillin 500 mg[/url]

  53. January 27, 2023 at 9:52 am

    [url=https://motilium.icu/]motilium cvs[/url]

  54. February 1, 2023 at 2:59 pm

    [url=http://zithromax.pics/]zithromax buy[/url]

  55. February 5, 2023 at 4:33 pm

    [url=https://xenical.site/]generic orlistat[/url]

  56. February 5, 2023 at 11:34 pm

    [url=http://erythromycintabs.quest/]erythromycin 250 mg for sale[/url]

  57. February 6, 2023 at 9:08 am

    [url=https://doxycycline2023.online/]can i buy 40mg doxycycline online[/url]

  58. February 7, 2023 at 5:59 pm

    [url=https://dexamethasonex.com/]dexamethasone 2.5 mg[/url]

  59. February 8, 2023 at 11:11 am

    [url=https://tetracycline.ink/]tetracycline hydrochloride[/url] [url=https://tetracycline.directory/]buy tetracycline 500mg online[/url] [url=https://phenergantabs.online/]phenergan cost[/url]

  60. February 8, 2023 at 9:27 pm

    [url=https://domperidonemotilium.shop/]purchase motilium online[/url]

Leave a Reply

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