在Git中撤消对一个文件的工作副本修改? [英] Undo working copy modifications of one file in Git?
问题描述
然而,我只想撤消那一个文件的工作副本更改,没有其他任何东西。
我可以这样做吗?
您可以使用
git checkout - 文件
不需要 -
(如nimrodm所示),但如果文件名看起来像分支或标记(或其他修订标识符),则可能会感到困惑,因此使用 - -
是最好的。
您也可以查看特定版本的文件:
git checkout v1.2.3 - file#tag v1.2.3
git checkout stable - file#stable分支
git checkout origin / master - file #upstream master
git checkout HEAD - 文件#最近提交的版本
git checkout HEAD ^ - file#最近提交之前的版本
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.
How do I do that?
You can use
git checkout -- file
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屋!