After some rebase, merge and git stash, sometimes I found myself in a bad git state, like a detached head state or in the middle of some messy conflict resolving, whatever that means. What to do?
First question to ask yourself, can I afford to throw away my current changes?
If the answer is yes, then there are many options. Here are a few:
[code] rm -rf git_dir/ git clone https://some.git.clone.path [/code]
This is probably the most noob way to back out from a bad state.
[code] git reset –hard HEAD [/code]
With git reset, you go back in history to the beginning of your current branch.
If the answer is no, then here are a few options:
[code] Use whatever cmds to tar/gzip your git directory. [/code]
Then assuming you are on your current branch called bad_branch, try
[code] git checkout master git checkout -b new_branch git checkout bad_branch – . [/code]
The last command will copy the changed files (instead of commits) over to your new_branch. Then you can do your clean up there. Your current new_branch will be one commit away from master (change this accordingly).