本文介绍了如何将Git托管项目中的所有本地更改恢复到以前的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行 git init 的项目。
在多次提交之后,我做了 git status ,它告诉我一切都是最新的,并且没有本地更改。

然后我做了几次连续的变化,并意识到我想把所有东西都扔掉,回到原来的状态。这个命令是否适合我?

  git reset --hard HEAD 


解决方案

如果您想恢复对工作副本所做的更改,请执行以下操作:

  git checkout。 

如果您想恢复对索引所做的更改(即,您已添加),请执行此操作。 ::

如果您想恢复您提交的更改,请执行以下操作:

  git revert< commit 1> <提交2> 

如果您想删除未追踪的文件(例如,新文件,生成的文件):

  git clean -f 



  git clean -fd 

或未跟踪的目录(例如新的或自动生成的目录) code>


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托管项目中的所有本地更改恢复到以前的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:22