Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: move a commit "on top"

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?

like image 909
Adrian Panasiuk Avatar asked Jan 24 '13 17:01

Adrian Panasiuk


People also ask

How do I reorder a commit in git?

Interactive Rebase also allows you to reorder commits. Simply drag and drop a commit between two existing commits to reorder history.

How do you move a commit to staged?

The closest that I know how to do is to copy all of the files that were changed in the commit to somewhere else, reset the branch to the commit before the commit that you're trying to move into the staging area, move all of the copied files back into the repository, and then add them to the staging area.

What is a git rebase?

What is git rebase? Rebasing is the process of moving or combining a sequence of commits to a new base commit. Rebasing is most useful and easily visualized in the context of a feature branching workflow.


Video Answer


1 Answers

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.

like image 172
Carl Norum Avatar answered Sep 19 '22 17:09

Carl Norum