问题描述
我有一个运行 git init
的项目。
在多次提交之后,我做了 git status
,它告诉我一切都是最新的,并且没有本地更改。
然后我做了几次连续的变化,并意识到我想把所有东西都扔掉,回到原来的状态。这个命令是否适合我?
git reset --hard HEAD
如果您想恢复对工作副本所做的更改,请执行以下操作:
git checkout。
如果您想恢复对索引所做的更改(即,您已添加),请执行此操作。 :: 如果您想恢复您提交的更改,请执行以下操作: 如果您想删除未追踪的文件(例如,新文件,生成的文件):
git revert< commit 1> <提交2>
git clean -f
git clean -fd
I have a project in which I ran git init
.After several commits, I did git status
which told me everything was up to date and there were no local changes.
Then I made several consecutive changes and realized I wanted to throw everything away and get back to my original state. Will this command do it for me?
git reset --hard HEAD
If you want to revert changes made to your working copy, do this:
git checkout .
If you want to revert changes made to the index (i.e., that you have added), do this. Warning this will reset all of your unpushed commits to master!:
git reset
If you want to revert a change that you have committed, do this:
git revert <commit 1> <commit 2>
If you want to remove untracked files (e.g., new files, generated files):
git clean -f
Or untracked directories (e.g., new or automatically generated directories):
git clean -fd
这篇关于如何将Git托管项目中的所有本地更改恢复到以前的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!