I would like to write a script that needs a clean working directory. I want to make sure that any rebases, merges, or anything else that might not have ended properly is completely gone from my working directory.
git reset --hard
should work for merges, and git rebase --abort
will work for rebases, but there are other states like reverting or cherry-picking as well. Is there any sure way to clear all such events in order to get my working directory into a clean state?
EDIT:
For example:
((5d8999f...))
$ git rebase develop
(detached HEAD|REBASE 1/3)
$ git reset --hard
(detached HEAD|REBASE 1/3)
$ git checkout HEAD -- .
(detached HEAD|REBASE 1/3)
$ git status
rebase in progress; onto 41e6808
You are currently rebasing.
(all conflicts fixed: run "git rebase --continue")
I know that I can do git rebase --abort
, but if there is no rebase going on that will cause an error, which I am not in the mood of dealing with. Also, since this will be an automatic script I do not want to find out that there may be other states that I may not have accounted for.
I need one foolproof way to revert my working directory to a pristine state so that I can do any command I want without failure.