繁体   English   中英

Git不会还原或提交它认为已修改的文件

[英]Git won't revert or commit a file that it thinks is modified

我按照本教程将SVN存储库转换为Git。 现在似乎无法提取此答案中建议的子存储库。

原谅长篇文章,但大部分文本都是格式良好的git输出。

操作系统:Windows 8命令行:MinGW Git版本:1.8.1.msysgit.1

除非您有一个干净的暂存区域且没有修改过的文件,否则提取子存储库的过程似乎不起作用。

git status告诉我,即使这是一个全新的SVN导入,我也有一个修改过的文件。 好吧,让我们试着摆脱它。

尝试并还原文件。

user$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")

user$ git checkout -- "folder with space/folder/toolbar.png"

user$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")

这不起作用,但我真的不在乎我是否提交它,所以我接下来会尝试。

user$ git commit -a -m "Testing if committing fixes it"
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")

user$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")

通过跳过暂存来提交不起作用,所以让我们先尝试暂存它。

user$ git add "folder with space/folder/toolbar.png"

user$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")

不行,所以我很难过......去找一个更聪明的人。

我是git的新手,但我很熟悉Hg,并且已经阅读了这个在线教程 ,让我自己开始。

我完全可能搞砸了一个简单的命令。

已经尝试过:我四处寻找解决我的特定问题的方法,但运气不佳。 我偶然发现了这个似乎相关的答案 ,但并没有完全解决我的问题。

编辑:可能有趣的事情这是令我困惑的部分。 我刚才把这个仓库推到了一个在线仓库。 在一个新的克隆之后,repo仍然认为该文件被修改(即git status返回相同的结果,我已经设置了git config --global core.autocrlf false并通过运行git config --global core.autocrlf验证git config --global core.autocrlf确实返回错误)。

编辑2:发现修复,但问题仍未解释我已设法通过简单地从系统,暂存区域中删除文件然后提交更改来修复存储库。 在此之后获取文件我只是将其复制回来并将其提交到存储库。

这个问题虽然已经解决,但只会让我更加困惑。

当我正在玩删除文件时,我注意到如果我将存储库重置为HEAD,其最后一次提交已删除文件,git status将指示没有任何更改,并且文件未被跟踪但文件将被还原在我工作的树上 考虑到它被标记为在git中删除,这很奇怪......

只有在第二次删除它之后,即使git不再记住它,我是否设法实际删除它以便git resetgit reset --hard不会恢复文件。

如果有人可以解释我是如何进入这种状态的,如果它是git或正常行为中的错误,我将非常感激。

我的怀疑我已经丢失了我使用的命令序列,但发生的事情是这样的:文件是Images/toolbar.png ,我已经导航到Images文件夹。

我从文件系统中删除它后,git检测到这样的变化:

# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted: toolbar.png
#       deleted: ../images/toolbar.png
#

请注意, images文件夹不是大写的! 这是在Windows中运行忽略路径的情况。 我怀疑这可能是问题的一部分......

我真的很困惑,但我的问题已经消失了。 所以这篇文章只是作为一种好奇心,尽管我无法复制它在SVN转换过程中的行为。

我有一段时间有类似的问题。

是否对此文件或其所在的目录进行了大写更改?

我有一个大写字母的目录,改为全部小写(让我们说它从/Foo变为/foo )。 它给了我你所描述的所有相同的问题。

每当我修改一个文件时,它给了我类似的输出:

#       modified: bar.txt
#       modified: ../Foo/bar.txt

我也有同样的问题,提交或重置没有产生任何结果。

我认为问题的原因是Windows文件路径不区分大小写,但Unix文件路径不区分大小写。 由于许多像Git这样的命令行工具都是在Unix-y系统上开发的,所以它们有时候不能很好地处理这种差异,并且当文件被添加为Foo/bar.txtfoo/bar.txt时会感到困惑。 。 我认为这让Git认为有两个不同的文件,实际上只有一个。

我的最终修复与您的相同,从历史记录中删除整个目录,然后重新添加它(并且永远不会再次更改大小写)。 这也引起了你所描述的同样的怪异,我必须在它花了两次之前删除它。

无论如何,我知道这不是一个明确的答案,但我已经能够重现这个问题,所以我很确定是什么导致了它(至少对我而言)。

我有一个类似的问题,因为我的计算机有两个同名的文件。

我一直得到的消息:

# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   images/contact_seller.GIF
#

之所以发生这种情况,是因为repo的初始提交是从MacBook完成的,格式化区分大小写,并且错误出现在我的iMac上,格式不区分大小写。

在区分大小写的计算机上,您可以看到两个文件

SwedishChef$ ls images/contact_seller*
images/contact_seller.GIF   images/contact_seller.gif

这在第二台机器上无效,所以git必须对它做点什么。

我只需要重命名文件并提交这些更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM