1

I'm merging one branch with another and I always have a conflict:

bicou@mba ~/AndroidStudioProjects/xxx (master) $ git status
On branch master
Your branch is ahead of 'origin/master' by 30 commits.
  (use "git push" to publish your local commits)

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Changes to be committed:

    modified:   alpha.sh

Unmerged paths:
  (use "git add <file>..." to mark resolution)

    both modified:   app/src/main/res/values-fr/strings.xml

So apparently strings.xml can't be merged automatically. However there are no differences: the only thing that is not merged is at the bottom of the file:

bicou@mba ~/AndroidStudioProjects/xxx (master) $ tail -5 app/src/main/res/values-fr/strings.xml
<<<<<<< HEAD
</resources>
=======
</resources>
>>>>>>> develop

Let's review both lines in hexa (whitespace, etc):

bicou@mba ~/AndroidStudioProjects/xxx (master) $ tail -5 app/src/main/res/values-fr/strings.xml | tail -2 | head -1 | xxd
00000000: 3c2f 7265 736f 7572 6365 733e 0a         </resources>.

and

bicou@mba ~/AndroidStudioProjects/xxx (master) $ tail -5 app/src/main/res/values-fr/strings.xml | head -2 | tail -1 | xxd
00000000: 3c2f 7265 736f 7572 6365 733e 0a         </resources>.

No difference. Why isn't git merging this automatically?

Edit: it appears it is a whitespace issue nonetheless, however I don't understand why it isn't stated in the merged file and only when manually diffing the files:

bicou@mba ~/AndroidStudioProjects/xxx (master) $ git diff develop -- app/src/main/res/values-fr/strings.xml
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index 5804034..2097f87 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -96,4 +96,4 @@
     <string name="fragment_min_max_set_button">Valider</string>
     <string name="fragment_min_max_clear_button">Effacer</string>
     <string name="drawer_name_no_account">Invité</string>
-</resources>
\ No newline at end of file
+</resources>

Note: this is not a Windows/Unix end of line issue. I don't use Windows at all, only LF. The issue may come from my editor which didn't add a new line character at the end of the file. That was the root issue.

Benoit Duffez
  • 11,839
  • 12
  • 77
  • 125

1 Answers1

1

It appears it is a whitespace issue nonetheless, however I don't understand why it isn't stated in the merged file and only when manually diffing the files:

bicou@mba ~/AndroidStudioProjects/xxx (master) $ git diff develop -- app/src/main/res/values-fr/strings.xml
diff --git a/app/src/main/res/values-fr/strings.xml 
b /app/src/main/res/values-fr/strings.xml
index 5804034..2097f87 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -96,4 +96,4 @@
     <string name="fragment_min_max_set_button">Valider</string>
     <string name="fragment_min_max_clear_button">Effacer</string>
     <string name="drawer_name_no_account">Invité</string>
-</resources>
\ No newline at end of file
+</resources>
Benoit Duffez
  • 11,839
  • 12
  • 77
  • 125
  • You're correct, it's the missing newline. Git is told to combine change set #1, which says "make some change that results in a file that ends *without* a newline", with change set #2, which says "make some change that results in a file that ends *with* a newline". These changes conflict. Now, how will you present the conflict to yourself, given that the method of showing a conflict is to write both sets of lines into one file? – torek Feb 24 '18 at 15:54
  • The same `\No newline at end of file` would be nice, as in the diff output. Or maybe on the same line as the branch name on which there is no newline, like `>>>>>>> develop (No newline at end of file)` – Benoit Duffez Feb 24 '18 at 16:26
  • I like that second method. It would need a fair amount of re-coding some internals in Git, I think, but it seems like the best way to display the problem. – torek Feb 24 '18 at 16:32