Bitbucket CRLF问题?

shr*_*anp 6 git merge bitbucket pull-request

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

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

  1. Developer创建了一个pull请求,将featurebranch1合并到sprintbranch中
  2. 如果存在合并冲突,开发人员会将sprintbranch合并到featurebranch1并创建拉取请求以将featurebranch1合并到sprintbranch中.

两次bitbucket都表明整个文件已经改变.并且没有合并冲突.

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

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

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

更新:

我刚刚发现我可以w=1在pull请求的url末尾添加一个查询字符串来忽略cr lf差异.

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

Arj*_*jan 9

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

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

* text eol=lf
Run Code Online (Sandbox Code Playgroud)

此Github帮助页面显示了更多信息.(该信息通常用于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"
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅Github文章.

  • 我添加了一个带有 `* text eol=lf` 的 .gitattributes(并提交了它),并期望很多文件会自动修改并修复行尾。那没有发生。对行尾的更改何时反映在我的回购中? (2认同)