Issue: Bitbucket shows that the entire file has changed even though I dont see any differences. And there are no merge conflicts in these files.
Details: I created a sprint branch (named "sprintbranch") and the developers created a feature branch(named "featurebranchX") from the sprint branch. I started merging feature branches back to the sprint branch as and when features were implemented. Now there are two scenarios where I face an issue:
Both times bitbucket shows that the entire file has changed. And there are no merge conflicts.
When this happens, I cannot do a code review since I dont know what specific lines have been modified by the developer. Also I lose history at this point - looking back I wont be able to figure out what was implemented or merged into the sprint branch.
My guess is that the issue is with line endings. Something to do with CRLF. But when I commit my work I do see that the appropriate line endings are being used automatically (either by git or by the tool like SmartGit)
How do I resolve this so it doesnt keep happening?
Update:
I just found out that I can append a query string w=1
at the end of a url of a pull request to ignore cr lf differences.
But these files are still there in the commit and when I do merge it back, it will include those differences right?
Even though Bitbucket can ignore whitespace in diffs (using the w=1
query parameter), those changes will still be included in the merge.
But you can configure git to convert all line endings to either LF or CRLF. Your team should first decide which option it will be, and then set the text
property in the .gitattributes
file accordingly, like so:
* text eol=lf
This Github help page shows more information. (The information is for git in general, not specifically Github.)
You also need the global configuration option git config --global core.autocrlf input
(Mac & Linux) or git config --global core.autocrlf true
(Windows).
# Make sure you won't lose 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With