【发布时间】:2010-12-14 17:03:09
【问题描述】:
我有一个修改过的文件,我想恢复到最新提交中的任何内容,但它“卡在”那里总是被标记为已修改。
$ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: index.php
#
no changes added to commit (use "git add" and/or "git commit -a")
然后我试试:
$git checkout -- index.php
但是 git status 的输出还是一样的。然后我尝试:
$git reset --hard master
HEAD is now at 02c9613 test commit message
而且 git status 的输出还是一样的。
关于如何摆脱对该文件的假定更改有什么想法吗?
【问题讨论】:
-
有哪些修改?
-
git diff的结果是什么。闻起来像stackoverflow.com/search?q=[git]+autocrlf。 -
差异主要显示行尾更改。请注意,我根本没有更改此文件。这来自团队的一位新成员。我会看看 Rudi 的链接。
-
如果“文件”实际上是一个文件夹,并且差异表明该行从
Subproject commit hash1更改为Subproject commit hash2,这意味着您的项目中有一个子模块,您需要对其进行更新。在这种情况下,请执行git submodule foreach git pull。如果现在显示hash1更改为hash3,请进入子模块文件夹(“文件”)并执行git checkout hash1。还有other ways to do the submodule update,但这对我有用。
标签: git git-checkout git-reset