windows 处理 Git 拒绝重置的文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1206406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dealing with files that Git refuses to reset?
提问by jkp
I and my collegues are having terrible trouble getting git
to behave properly with certain files on our Windows repostiory clones. The clones have been made by cloning a repository which originates on an OSX machine. We have set autocrlf to true, but the problem is that we reguarly find files that git
thinks are changed even though we never touch them (we don't even open them in an editor.
我和我的同事git
在处理我们的 Windows 存储库克隆上的某些文件时遇到了严重的麻烦。克隆是通过克隆源自 OSX 机器的存储库来制作的。我们已将 autocrlf 设置为 true,但问题是我们经常发现git
认为已更改的文件,即使我们从未接触过它们(我们甚至不在编辑器中打开它们。
The following output illustrates the issue: any ideas where I am going wrong?
以下输出说明了这个问题:我哪里出错了?
$ git status
# On branch master
# Your branch is behind 'origin/master' by 27 commits, and can be fast-forwarded.
#
# 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: Web Applications/webclient/language/en/lang_copyitems.ini
#
no changes added to commit (use "git add" and/or "git commit -a")
Administrator@windows-dev ~/Documents/Workspace/prestige.git
$ git diff "Web Applications/webclient/language/en/lang_copyitems.ini"
diff --git a/Web Applications/webclient/language/en/lang_copyitems.ini b/Web Applications/webclient/language/
index 800c188..ed11c0e 100644
--- a/Web Applications/webclient/language/en/lang_copyitems.ini
+++ b/Web Applications/webclient/language/en/lang_copyitems.ini
@@ -1,12 +1,12 @@
-<EF><BB><BF> [Header]
- Description=Language strings for 'copyitems.php'
-
- [Messages]
- 300=Copy
- 301=Close
- 302=COPY STORIES
- 303=Name
- 304=In Queue
- 305=New Name
- 306=Items to Copy
- 308=This item has mandatory metadata fields that are not correctly set. Click any part of this messag
+<EF><BB><BF> [Header]
+ Description=Language strings for 'copyitems.php'
+
+ [Messages]
+ 300=Copy
+ 301=Close
+ 302=COPY STORIES
+ 303=Name
+ 304=In Queue
+ 305=New Name
+ 306=Items to Copy
+ 308=This item has mandatory metadata fields that are not correctly set. Click any part of this messag
Administrator@windows-dev ~/Documents/Workspace/prestige.git
$ git checkout HEAD "Web Applications/webclient/language/en/lang_copyitems.ini"
Administrator@windows-dev ~/Documents/Workspace/prestige.git
$ git status
# On branch master
# Your branch is behind 'origin/master' by 27 commits, and can be fast-forwarded.
#
# 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: Web Applications/webclient/language/en/lang_copyitems.ini
#
回答by VonC
The problem with this settings, as illustrated by the GitHub guideis an automatic conversion is done during the checkoutof the repository...
此设置的问题,如GitHub 指南所示,是在检出存储库期间完成自动转换...
That means you do not need to open a file to trigger any change.
这意味着您无需打开文件即可触发任何更改。
Is it not possible to keep autocrlf
to false, and open those Windows files in editors able to respect the return line characters?
是否不能保持autocrlf
为 false,并在能够尊重回车行字符的编辑器中打开那些 Windows 文件?
Note (illustrated here), if you need the conversion, except for some files, you could add a .gitattributes in the parent directory, with a:
请注意(此处说明),如果您需要转换,除了某些文件,您可以在父目录中添加一个 .gitattributes,并带有:
myFile -crlf
In the file you set attributes to a path (or a pattern), or unset them (with the minus sign).
The crlf
attribute is the attribute which tells if a file is affected by the core.autocrlf
options. If you unset it, Git won't mess with the line endings in the file
在文件中,您将属性设置为路径(或模式),或取消设置(使用减号)。
该crlf
属性是指示文件是否受core.autocrlf
选项影响的属性。如果您取消设置,Git 不会弄乱文件中的行尾
回答by spyle
To solve this problem on my Windows 7 machine using git 1.7.3.1, I had to set the core.filemode option to false.
为了在我的 Windows 7 机器上使用 git 1.7.3.1 解决这个问题,我必须将 core.filemode 选项设置为 false。
git config -e --local