by SubuSS · 4y ago · 0 comments
git branch NEWBRANCH
git checkout master
git revert —hard HEAD^
If you want to continue working on the new branch you do
git checkout NEWBRANCH
Source: git branch --help
git branch some-new-branch-name
git reset HEAD~ --hard
git checkout some-new-branch-name
Which is correct, assuming master is already checked out.0. prior state is that we're on master and have committed something that should have been on a branch
1. create a new branch that is identical to master (i.e., contains the commit) -- note this does NOT checkout the new branch (`git checkout -b some-new-branch-name` would do that)
2. reset current branch (master) to point at the commit before (i.e., strips the commit from master)
3. checkout the new branch to continue work there
At the end, master doesn't contain the commit anymore, and the new branch does. It's all correct.