Question

I made a lot of unhelpful changes, and would like to revert to the state my repo was in before any of the changes.

Is there a git command for doing that?

Thanks!

Was it helpful?

Solution

First, to revert changes to tracked files:

git reset --hard HEAD

git reset alone resets the index; adding --hard resets the working copy as well. If you've already committed, specify a different commit to reset to - eg, HEAD^ to revert to the parent commit of HEAD (ie, to remove the latest commit).

Next, to delete all untracked files:

git clean -dfx

-d tells it to delete directories, -f forces it to actually do the delete, and -x skips .gitignored files.

OTHER TIPS

If I understand correctly you have committed something and want it reverted git reset --hard HEAD^

If you haven't committed anything and it's only your working tree that is messed up then git reset --hard HEAD

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top