【发布时间】:2011-01-19 13:15:58
【问题描述】:
这是git log 的输出:
* 5a831fdb34f05edd62321d1193a96b8f96486d69 HEAD (HEAD, origin/work, work)
| LIB/xxx.cpp | Bin 592994 -> 593572 bytes
| LIB/xxx.h | 5 +++++
| LIB/bbb/xxx.h | 9 +++++++++
| LIB/aaa/xxx.cpp | Bin 321534 -> 321536 bytes
| LIB/aaa/yyy.cpp | 31 +++++++------------------------
| tests/aaa/xxx.cpp | 29 +++++++++++++++++++++++++++++
| tests/test_xxx.vcproj | 4 ++++
| 7 files changed, 54 insertions(+), 24 deletions(-)
为什么它把一些文件当作二进制文件,而另一些不是?这会带来严重的问题,因为 git 也不想自动合并它们。因此,几乎所有的合并/变基/拉取操作都变得很痛苦。
这里是 repo 配置:
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = https://xxx/project.git
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "work"]
remote = origin
merge = refs/heads/work
[svn-remote "svn"]
url = xxxx
fetch = :refs/remotes/git-svn
在主 .gitconfig 中也是 core.autocrlf = false。
编辑 我按照 cmets 中的建议将 core.autocrlf 设置为 true,但这似乎不会影响我之后的下一次合并(也许现在更改 autocrlf 为时已晚?还是与问题无关?):
> git merge work
warning: Cannot merge binary files: LIB/xxx.cpp (HEAD vs. work)
warning: Cannot merge binary files: LIB/aaa/xxx.cpp (HEAD vs. work)
Auto-merging LIB/xxx.cpp
CONFLICT (content): Merge conflict in LLIB/xxx.cpp
Auto-merging LIB/xxx.h
Auto-merging LIB/aaa/xxx.cpp
CONFLICT (content): Merge conflict in LIB/aaa/xxx.cpp
Automatic merge failed; fix conflicts and then commit the result.
现在 gits 还坚持要更改几个文件中的换行符(这是我不想要的)。
解决方案
感谢:
*.cpp -text crlf diff
需要-text 部分来防止 git 转换 lineends,即使 core.autocrlf 设置为 false。
【问题讨论】:
-
那么为什么
core.autocrlf=false? -
我的理解是,这使得 git 根本不转换任何行尾,即让我看到文件原样,这就是我所追求的。这不正确吗?
-
不完全是。
autocrlf设置为 true,git 使用 lineendings 转换来获取文件的内部表示。我建议将选项设置为true- 或者至少尝试一下。
标签: git