在Git中撤消对一个文件的工作副本修改? [英] Undo working copy modifications of one file in Git?

查看:94
本文介绍了在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆