标签云

微信群

扫码加入我们

WeChat QR Code

This question already has an answer here:How to revert a Git repository to a previous commit41 answersI know that Git tracks changes I make to my application, and it holds on to them until I commit the changes, but here's where I'm hung up:When I want to revert to a previous commit I use: git reset --hard HEADAnd Git returns:HEAD is now at 820f417 microHow do I then revert the files on my hard drive back to that previous commit?My next steps were:git add .git commit -m "revert"But none of the files have changed on my hard drive...What am I doing right/wrong?


What do you mean by reverting the files on my hard drive back to that previous commit? If 820f417 is your desired commit, the files should now have the exact content in that commit.

2019年05月22日49分23秒

If you want to undo all changes, after git reset --hard, you should git checkout <branch>.

2019年05月23日49分23秒

I really don't get the idea of [duplicate] then ask a new question, when the answers are not satisfactory. It's a recipe for disaster in terms of more duplicates....

2019年05月22日49分23秒

git reset --soft HEAD{1} really messed up my local repository. It thinks all the files are now. What do I do now?

2019年05月22日49分23秒

Mark Longair: the answer you point to at the end does not user --hard, but instead simply git reset.

2019年05月22日49分23秒

MiniQuark: I'm using the equivalent and slightly shorter variant that I suggested in the comments on the linked answer.

2019年05月22日49分23秒

Thanks for the tip about git reset --soft HEAD{1}. I haven't thought of that way of reverting commits, even though I'm experienced in git.

2019年05月22日49分23秒

One can also consult git reflog in the event that git log does not immediately show the relevant commit you wish to revert to.

2019年05月22日49分23秒

git clean -xdf is what you want :)

2019年05月22日49分23秒

This is the first git command I've come across so far that's irreversible... added a warning so others don't get too trigger happy...

2019年05月22日49分23秒

Use n instead of f first, to see a list of what will be removed, e.g: git clean -xdn

2019年05月22日49分23秒

remember to be careful with clean because git clean -f will remove any environment/gui project folders (e.g. .idea (phpstorm) or .vagrant (vagrant))

2019年05月22日49分23秒

Goddamnit, git clean -xdf even removes all ignored files!!!

2019年05月22日49分23秒