How to move last commits to between branches in Git
If you have accidently made commits onto a branch and now want to move them commits to a new branch or and existing branch here is how to do it.
#Scenario Here is an scenario where we have made three commits onto master but now want ot move them last three commits on to a new branch.
#Moving commits to a new branch First create a new branch. The new branch will now point to latest commit (E). Then reset the original branch back to the original commit (B). Then change on to the new branch. The C, D, & E commits are now only on the new branch.
#Moving to an existing branch The C, D, & E commits will first need to be moved onto the existing branch. To do this checkout the existing branch and then merge the changes from the master in to the existing branch. Then reset the master branch back to commit B. The C, D, & E commits are now only on the existing branch.
** Be very careful with the git reset –hard command as you can lose work **
blog comments powered by Disqus