Git: move a commit "on top"

Adrian Panasiuk picture Adrian Panasiuk · Jan 24, 2013 · Viewed 25.4k times · Source

Let's say in master I have a feature disabled. I work on that feature on branch feature, so I have a special commit $ there that just enables that feature. Now I want to merge the changes I did in feature into master, but keep the enabling commit out. So it's like

main:    A--B--X--Y
feature: A--B--$--C--D

So let's say I want to do it, by moving the $ commit on top of feature:

new feature: A--B--C--D--$

How would I go about doing that?

Answer

Carl Norum picture Carl Norum · Jan 24, 2013

git rebase -i B, and then move $ to the end of the list that shows up in your editor. It will start out as the first line in the file that opens. You could also just delete that line entirely, which will just drop that commit out of your branch's history.