Search This Blog

Sunday, June 24, 2012

Git combine (merge) local commits into one

This tutorial is for those of you who used ToirtoiseGit which has the option of combining local commits before pushing them to the remote source and want to use that option in other Git clients.

To combine (merge) local commits into one before pushing them:

1. Switch to your local branch where your commits reside (actually it does NOT have to be a different branch, you can combine git commits on your local master as well)

2. I suppose you have already made 3 commits which you want to combine (merge) into one.

3. Reset (soft) as many commits down as you want to combine in your branch. When you execute a soft reset on a branch you end up having the combined result of the commits in your index ready to commit.

4. Commit the changes from your index - you end up having a single commit which a combined (merged) result of the previous three.



Screenshots were done using "SmartGit" from syntevo.

4 comments:

  1. Thanks, exactly what I needed to know. So simple too!

    ReplyDelete
  2. My colleagues were looking for 2014 CA FTB 3500 earlier this week and encountered a document management site with lots of form templates . If you need 2014 CA FTB 3500 too , here's http://pdf.ac/9Qn240

    ReplyDelete
  3. Savvy blog post , Just to add my thoughts , if others is requiring to merge two PDF files , my colleague found a tool here AltoMerge and also here http://pdf.ac/5GEHkM

    ReplyDelete
  4. Clever idea. Am relatively new to Git and am familiar with the usual way to do this (via interactive rebasing, squashing unwanted commits), but never gave your idea any thought (though I'm comfortable with reset). Much easier than the rebase route (hopefully no downside but will think about it). Thanks!

    ReplyDelete

If you like this post, please leave a comment :)