Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

git - 如何将Git托管项目中的所有本地更改还原到以前的状态?(How do I revert all local changes in Git managed project to previous state?)

I have a project in which I ran git init .

(我有一个项目,我在其中运行git init 。)

After several commits, I did git status which told me everything was up to date and there were no local changes.

(几次提交后,我做了git status ,告诉我一切都是最新的,没有本地更改。)

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
  ask by Jacques René Mesrine translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 (ie, 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 (eg, new files, generated files):

(如果要删除未跟踪的文件(例如,新文件,生成的文件):)

git clean -f

Or untracked directories (eg, new or automatically generated directories):

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

git clean -fd

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...