I have a local branch with commits like: head/master 5 4 3 2 1
I want to move 3 to the head and not lose any other commits: head/master 3 5 4 2 1 Is this what rebase is for? (Obviously, I'm new)
Ideas? thanks in advance
I have a local branch with commits like: head/master 5 4 3 2 1
I want to move 3 to the head and not lose any other commits: head/master 3 5 4 2 1 Is this what rebase is for? (Obviously, I'm new)
Ideas? thanks in advance
Use git rebase:
git rebase -i HEAD~5
After HEAD~
there is number five - it is the same as the commits you have. After executing this command, your editor* should run. It has a list of your last 5 commits (remember HEAD~5
?). Now change the position of commit(s) on the list of commits you are presented and save and close the editor. You are done. The position of commits have changed.
*
How do I make Git use the editor of my choice for commits?
If what you want to do is to reorder the revisions, it's simple enough:
git checkout 2
git cherry-pick 3..5 # this will discard revision 3 so changes from revisions 4 and 5 will be applied
git cherry-pick 3 # apply change from revision 3
# if you like the result
git branch -f master
git checkout master
# push -f if needed because you rewrote history