Git merge with "Untraceable working tree file" merge when changing case

On Mac OS X, I have two branches - say A and B - and I want to merge A into B. When I try to make git merge A on B, I get:

 error: Untracked working tree file 'path/file.php' would be overwritten by merge. Aborting 

This is due to the fact that some change in A renamed to a file, that is, B has the file path/File.php , and A renamed it to path/File.php . Because the Mac OS X file system is case insensitive, this probably confuses git. Is there a way to make git merge correctly?

Update: for clarification, branch B has no uncommitted changes, and the file in question is tracked in both branches (under different names, of course).

+6
source share
4 answers

Maybe this answer to another question will be useful; you may just want to temporarily enable this option ...

git mv and only change directory case

+2
source

OK, after digging all day, here is the solution I found:

=========== Situation ===========

I am developing on my branch "Hotdog"

My employee pushed his work to our master branch, including a file called "Hamburgersrule"

I merge the master into my Hotdog branch.

My colleague changes “Hamburgersrule” to “HamburgersRule" and pushes him to mastery.

=========== Problem ===========

When I try to switch between Hotdog and Master, Git thinks that some changes have occurred. The HamburgersRule case is different from Git, but windows think it's just fine. Every time I try to merge or check another branch, Git warns me that I will lose my uninstalled files.

I can suppress the message by setting Git config core.ignorecase true, but the main problem still exists, and ignoring the differences between the cases is what led us to this mess in the first place.

=========== Solution ===========

1: Make a triple rename on the Wizard (to make sure the new file name is correct) HamburgersRule → HamburgersRule_Rename → HamburgersRule

2: Merge this change into the Hotdog branch. For the merge to work, you need to uninstall your version of "Hamburgersrule" (using your OS, not git)

3: Clean up the remaining files in Hotdog. Check if the merge works as expected. You may need to check the hamburgers in the Host section:

git checkout master HamburgersRule

EDIT: Important note. If you do not want to fix this problem again and again, make sure your colleagues have ignorecase set to false

git config core.ignorecase false

If someone ignores case sensitivity, their Git client ignores the changes and continues to check for the wrong name.

+4
source

Running git 2.0.1 (June 25, 2014), this merge will not be anymore.

See pass ae352c7f37ef2098e03ee86bc7fd75b210b17683 by David Turner ( dturner-tw )

merge-recursive.c : fix merge file change merge

In a case-insensitive file system, when merging, the file will be mistakenly deleted from the working tree if the incoming commit renamed it, changing only its case.
When the rename merges, the file with the old name will be deleted, but since the file system considers the old name to be the same as the new name, the new file will actually be deleted.

We avoid this by not deleting case cloned files in the index in step 0.

+3
source

How about git mv path/File.php path/file.php on B ? This should let git know the same file with a different name.

0
source

Source: https://habr.com/ru/post/893022/


All Articles