我和我的同事一直在努力解决这个问题。它有很好的文档记录(页面末尾的一些链接),但到目前为止我还没能解决这个问题。我们使用visual studio 2013在c#中编码。
每当我们合并两个分支时,我们就会有大量的“更改”,其中一个文件完全由相同的文件替换。从我在网上看到的内容来看,我几乎可以肯定这是由于行结尾的问题。
以下answer是最能帮助我的人。我第一次按照步骤操作时,只能找到要规范化的单个文件,即.gitattributes文件。但后来我将文件替换为下面的文件作为第一步,并找到了预期归一化的文件。这一切都在我当地的分支机构完成。
# Set the default behaviour, in case people don't have core.autocrlf set.
* text=auto
# Explicitly declare the text files you want to always be normalised and converted
# to native line endings on checkout.
*.cs text
*.json text
*.html text
*.csproj text
# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.gif binary
我完成了接下来的步骤,输入命令后我收到了预期的消息(下面):“git add -u”
消息:
警告:CRLF将被(...)
中的LF替换
然而,当我切换到主分支并从我的本地分支更新时,几个文件再次被替换。我尝试在master分支中创建相同的.gitattributes文件并再次执行步骤,但是在“git status”命令之后找不到应该规范化的文件,并且合并总是像以前一样执行,替换了几个文件相同的。
我做错了什么?
答案 0 :(得分:2)
问题是我没有将我的代码分支与gitattributes文件同步(推送)到存储库,我只是提交了它。因为我在当地工作,我觉得这已经足够了。但它不是,并且合并得到了以前版本的代码,没有gitattributes文件。这个问题非常天真,但由于我上面引用的文档没有帮助,我将在下面发布我自己的教程,这可能会避免将来的github noobs做同样的错误。我的教程主要基于thread。
对于本教程,我们假设存在工作分支和主分支。我们的想法是将gitattributes文件推送到工作分支,下载主分支的代码并使用工作分支更新该代码。
# Add the following content to a file on the root of the repository in the
# working branch, and name it .gitattributes
----------------------------------------------------------------------------
# Set the default behaviour, in case people don't have core.autocrlf set.
* text=auto
# Explicitly declare the text files you want to always be normalised and converted
# to native line endings on checkout.
*.cs text
*.json text
*.html text
*.csproj text
# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.gif binary
----------------------------------------------------------------------------
# From the root of the repository in the working branch remove everything from the index
# (don't forget the '.')
git rm --cached -r .
# Re-add all the deleted files to the index
# (You should get lots of messages like:
# warning: CRLF will be replaced by LF in <file>.)
git diff --cached --name-only -z | xargs -0 git add
# Commit
git commit -m "Fixed the line ending issue"
# Sync the code
# Switch to the master branch
# Update (merge) from the working branch