Wednesday, June 14, 2017

Merge 2 commits when there are commits in between

Super handy trick based on based on https://stackoverflow.com/questions/30704254/merge-two-commits-where-commits-are-between

Lets say we have 2 commit we want to merge

f68ffb5 commit 6
...
d294fac commit 1


This is important: you have to give reference to a commit before the first one involved (in this case, the one that you want to squash to). Here we make the "before" reference with ^.

# rebase to the commit **before** commit 1
git rebase -i d294fac^

You invoked an interactive rebase. An editor window opens. Rearrange commits as desired (read the notes in the editor that opens)

In this list the commits go in reverse order (not as in git log): from the earliest to the latest.

Rearrange lines in the following way:

pick d294fac     //--- commit 1
squash f68ffb5   //--- commit 6
pick       //--- commit 2
pick       //--- ommit 3
pick       //--- commit 4
pick       //--- commit 5


or (leave the squashed commits in last place)
pick d294fac     //--- commit 1
squash f68ffb5  
//--- commit 6
pick      
//--- commit 2
pick      
//--- ommit 3
pick      
//--- commit 4
pick      
//--- commit 5

3 comments:

  1. Excellent blog, you gave very useful information about USA Dedicated Server in it. Thanks and keep posting.

    ReplyDelete
  2. Wow, this blog is very nice; I love this blog post. It is too much beneficial to me. And I think this blog helps all online business users with a situation with their business performance. India VPS Server

    ReplyDelete
  3. amazing blog The quality and depth of your blog posts are greatly appreciated. It's a great resource for bloggers generally. You do more than just outline the steps involved in starting a blog; you also provide guidance on selecting a suitable topic. If you want to build and create websites that last for years and adapt to your business's changing needs, you need a solid WordPress platform. As an additional resource, check out Why You Should Choose WordPress for Your Website?

    ReplyDelete