Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you move a commit back up the tree/in time with git?

Tags:

git

Is it possible to move the changes in a commit to before other changes on the tree so I can test those commits.

In this example I want to move 'Romoved sess_match_useragent' to before 'Updated core to 2.1.0' in the tree

mytree

Thanks

like image 416
Ben Avatar asked Sep 06 '25 03:09

Ben


1 Answers

Yes, with git rebase -i refspec.

Here, refspec will be the identifier (either a SHA1 or a relative refspec) of the commit preceding your "Updated core" commit. This will open an editor with the commits and their order: move the pick line for your commit right before the "Updated core" one and quit the editor: git will rewrite the branch.

Note that you may have to solve conflicts, however.

Read the help in the editor along with the list of commits, too: it contains a lot of useful tips, you can do plenty. For instance, just reword commit messages if you have made spelling mistakes...

In your case, as pointed out, refspec can he HEAD~17, ie "17 commits before ref HEAD" (HEAD is always the tip of the branch you are currently on).

like image 80
fge Avatar answered Sep 07 '25 21:09

fge