Oh shit, git (2016)
# create a new branch from the current state of master git branch some-new-branch-name # remove the commit from the master branch git reset HEAD~ –hard git checkout some-new-branch-name # your commit lives in this branch now
Note: this doesn’t work if you’ve already pushed to origin, and if you tried other things first, you might need to instead of . # undo the last commit, but leave the changes available git reset HEAD~ –soft git stash # move to the correct branch git checkout name-of-the-correct-branch git stash pop git add . git checkout name-of-the-correct-branch # grab the last commit to master git cherry-pick master # delete it from master git checkout master git reset HEAD~ –hard
Oh shit, I tried to run a diff but nothing happened?!
Source: ohshitgit.com