如何从命令行进行 git-revert?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5339518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I git-revert from the command line?
提问by ripper234
When I do git revert via TortoiseGit, I get this lovely window :
当我通过 TortoiseGit 执行 git revert 时,我得到了这个可爱的窗口:
However, when I want to do the same from the command line, the documentationmanages to completely confuse me. How do I revert all local uncomitted changes?
但是,当我想从命令行执行相同操作时,文档设法使我完全困惑。如何还原所有本地未提交的更改?
回答by William Pursell
To discard all local changes, you do not use revert. revert is for reverting commits. Instead, do:
要放弃所有本地更改,请不要使用还原。revert 用于恢复提交。相反,请执行以下操作:
$ git reset --hard
Of course, if you are like me, 7 microseconds after you enter that command you will remember something that you wish you hadn't just deleted, so you might instead prefer to use:
当然,如果您像我一样,在输入该命令 7 微秒后,您会记住一些您希望没有删除的内容,因此您可能更喜欢使用:
$ git stash save 'Some changes'
which discards the changes from the working directory, but makes them retrievable.
它丢弃工作目录中的更改,但使它们可检索。
回答by Marc Hughes
Assuming you haven't committed yet, you can also:
假设你还没有提交,你还可以:
git checkout filename(s)
回答by Joerg Rade
Git newbies like me should be aware that working directory' != pwd
.
像我这样的 Git 新手应该知道working directory' != pwd
.
It rather means the whole tree.
而是指整棵树。
So I'm thankful for Williams recommendation to use:
所以我很感谢威廉姆斯推荐使用:
$ git stash save 'Some changes'
which can be undone via the following:
可以通过以下方式撤消:
$ git stash pop