Bitbucket CRLF问题?

时间:2016-04-19 19:16:32

标签: git merge bitbucket pull-request

问题: Bitbucket显示整个文件已经改变,即使我没有看到任何差异。并且这些文件中没有合并冲突。

详细信息: 我创建了一个sprint分支(名为“sprintbranch”),开发人员从sprint分支创建了一个功能分支(名为“featurebranchX”)。当功能实现时,我开始将功能分支合并到sprint分支。现在有两种情况我面临一个问题:

  1. 开发人员创建拉取请求以将featurebranch1合并到sprintbranch
  2. 如果存在合并冲突,开发人员会将sprintbranch合并到featurebranch1并创建拉取请求以将featurebranch1合并到sprintbranch中。
  3. 两次bitbucket都显示整个文件已经更改。并且没有合并冲突。

    当发生这种情况时,我无法进行代码审查,因为我不知道开发人员修改了哪些特定行。此外,我在这一点上失去了历史 - 回顾过去,我无法弄清楚实施或合并到sprint分支中的内容。

    我的猜测是问题在于行结尾。与CRLF有关。但是当我提交我的工作时,我确实看到自动使用了适当的行结尾(通过git或像SmartGit这样的工具)

    如何解决这个问题,以免它继续发生?

    更新

    我刚刚发现我可以在拉取请求的url末尾附加一个查询字符串w=1,以忽略cr lf差异。

    但是这些文件仍然存在于提交中,当我将其合并回来时,它会包含这些差异吗?

1 个答案:

答案 0 :(得分:8)

尽管Bitbucket可以忽略差异中的空白(使用w=1查询参数),但这些更改仍将包含在合并中。

但您可以配置git将所有行结尾转换为LF或CRLF。您的团队应首先确定它将是哪个选项,然后相应地在text文件中设置.gitattributes属性,如下所示:

* text eol=lf

This Github help page显示更多信息。 (这些信息一般用于git,而不是Github。)

您还需要全局配置选项git config --global core.autocrlf input(Mac& Linux)或git config --global core.autocrlf true(Windows)。

# Make sure you won't loose your work in progress
$ git add . -u
$ git commit -m "Saving files before refreshing line endings"

# Remove every file from the git index
$ git rm --cached -r .

# Rewrite the git index
$ git reset --hard

# Prepare all changed files for commit
$ git add .
# It is perfectly safe to see a lot of messages here that read
# "warning: CRLF will be replaced by LF in file."

# And commit.
$ git commit -m "Normalize all the line endings"

More information is available in the Github article.

相关问题