撤消 Git 中一个文件的工作副本修改? [英] Undo working copy modifications of one file in Git?
问题描述
在上次提交后,我修改了工作副本中的一堆文件,但我想撤消对其中一个文件的更改,例如将其重置为与最近提交相同的状态.
After the last commit, I modified a bunch of files in my working copy, but I want to undo the changes to one of those files, as in reset it to the same state as the most recent commit.
但是,我只想撤消仅对那个文件所做的工作副本更改,而没有其他任何内容.
However, I only want to undo the working copy changes of just that one file alone, nothing else with it.
我该怎么做?
推荐答案
可以使用
git checkout -- file
你可以不用 --
(如 nimrodm 建议的那样),但如果文件名看起来像一个分支或标签(或其他修订标识符),它可能会混淆,所以使用 <代码>-- 最好.
You can do it without the --
(as suggested by nimrodm), but if the filename looks like a branch or tag (or other revision identifier), it may get confused, so using --
is best.
您还可以查看文件的特定版本:
You can also check out a particular version of a file:
git checkout v1.2.3 -- file # tag v1.2.3
git checkout stable -- file # stable branch
git checkout origin/master -- file # upstream master
git checkout HEAD -- file # the version from the most recent commit
git checkout HEAD^ -- file # the version before the most recent commit
这篇关于撤消 Git 中一个文件的工作副本修改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!