git: Reset Repository into a Clean State

Viewed 272

I'm looking for a way to "reset" a repository into a clean state. Hold up! Before you say

  • just use git-clean
  • ... or git-reset

this is not what I am looking for! I don't want to reset files, but state. That means, aborting all in-progress operations like rebases, merges, bisect, and removing any auxiliary files like MERGE_HEAD or MERGE_MSG inside the .git directory itself.

I could do it manually of course with a series of commands, but I was hoping for something more elegant that doesn't require me to know what state the repo currently is in.

1 Answers

You can look at the scripts provided in git/contrib : git-completion.bash contains a __git_ps1 function which will scan the different files in the .git folder to build a message stating REBASE ..., MERGE ... etc ...

You could use that to run the correct --abort command.

It's the closest thing to a git command that I know of which indicates what action is currently taking place.

You can also look into the code of this function, and see the list of checks it does to determine if it is in a merge state, or a rebase, or a cherry-pick.

Related