开发者

What is the git command to erase all changes and revert to the state of your last commit?

开发者 https://www.devze.com 2023-03-07 04:45 出处:网络
I made a lot of unhelpful changes, and would like to reve开发者_StackOverflow社区rt to the state my repo was in before any of the changes.

I made a lot of unhelpful changes, and would like to reve开发者_StackOverflow社区rt to the state my repo was in before any of the changes.

Is there a git command for doing that?

Thanks!


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号