Friday, 20 April 2012

Move a recent git commit and work in progress to another branch

Thanks to @LukeCarrier !!

The Issue

I had already pushed the master and moved onto writing code for ticket 324. I did a commit on the master the night before then continued coding the next day.

I then wanted to move the code to a test branch and remove from the master.

The solution

git status
git stash
git status
git reset --soft HEAD^
git status
git log
git reflog
git checkout -b ticket324
git status
git stash list
git stash pop
git commit
git checkout master
git status

The git stash saved todays changes. The git reset -- soft HEAD^ reverted the commit I made the previous night.

I then created a new branch with git checkout -b ticket324.

The restored the changes saved in the stash with git stash pop.

Then did a git commit to save my changes the the branch ticket324.

And then double checked the master branch to make sure the changes had been removed.

No comments:

Post a Comment