3days since the last Git and AI fuck-up

How to move accidentally committed changes to a brand new branch in git?

Mandeep Singhfrom the archive

shell
# create a new branch from the current state of master
git branch some-new-branch-name
# this is were your commit will live :)
shell
# now go back to master
git checkout master
# remove the commit from the master branch
git reset HEAD~ --hard
# whoola!! you are back on track

the other way of doing this:

shell
# 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 . # or add individual files
git commit -m "your message here"
# now your changes are on the correct branch

Many people suggest using cherry-pick for this situation, too, so take your pick on whatever makes the most sense to you!

yet another way:

shell
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
Originally Posted On: OhShitGit

Tagged accidents-recovery, git-commit, git-reset, git-stash, git-checkout, git-cherry-pick