无法解决git的行尾问题

库蒂尼奥

我和我的同事们一直在为这个问题而苦苦挣扎。它已经被很好地证明了(页面末尾的一些链接),但是到目前为止我还不能解决这个问题。我们使用Visual Studio 2013在C#中进行编码。

每当我们合并两个分支时,就会有大量的“更改”,其中一个文件完全被一个相同的文件替换。根据我在网上可以阅读的内容,我几乎可以肯定这是由于行尾存在问题。

以下答案是对我帮助最大的一个。我第一次执行这些步骤时,它只能找到一个要标准化的文件,即.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分支并从本地分支进行更新时,又一次替换了几个文件。我试图在master分支中创建相同的.gitattributes文件,然后再次执行以下步骤,但是在“ git status”命令之后找不到应该标准化的文件,并且合并操作始终如以前一样进行,替换了多个文件由相同的。

我做错了什么?

堆栈溢出线程

官方github解决方案

库蒂尼奥

问题是我没有将代码分支和gitattributes文件同步(推送)到存储库,而是提交了。因为我在本地工作,所以我认为就足够了。但这不是,并且合并正在获取代码的先前版本,而没有gitattributes文件。这个问题非常幼稚,但是由于我上面引用的可用文档没有帮助,因此我将在下面发布自己的教程,这可能避免将来的github noobs犯同样的错误。我的教程主要基于此线程

对于本教程,我们假设存在一个工作分支和一个master分支。想法是将gitattributes文件推送到工作分支,下载master分支的代码,并使用工作分支更新该代码。

# 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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章