以下是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也不想自动合并它们。因此,几乎所有的合并/变基/拉取操作都变得很痛苦。
这是存储库配置:
[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。
编辑 根据评论的建议,我将 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坚持要更改几个文件中的行尾(这是我不想要的)。
.gitattributes
中设置什么,Git 都会认为它是二进制的。 - user456814