Search code examples
gitmergerename

Disable Git Rename Detection


  1. I have a file, foo.txt
  2. Create and checkout branch 'branch_A'
  3. git mv foo.txt bar.txt followed by git add -A then git commit -m "renamed foo.txt"
  4. Checkout master, git checkout master
  5. remove foo.txt and commit.
  6. Now merge branch_A, git merge branch_A

And with this, I get an merge conflict (rename/delete).

CONFLICT (rename/delete): Rename foo.txt->bar.txt in branch_A and deleted in HEAD

This makes sense and is what I'd expect. However, I'd like to know if there is a way for git merge to not detect renames, but instead treat them as added/deleted. In this case, I'd expect git to detect that foo.txt was deleted and simply add bar.txt. No conflict.

I've tried using -X rename-threshold, but it has not worked for me. I've tried thresholds 0 and 120 (a number above 100). What am I missing?

Thanks!

P.S. I'm also getting error: refusing to lose untracked file at... errors. What does this mean?


Solution

  • Can you try with:

    git merge -s resolve branch_A
    

    This will enable resolve merge strategy, which does not try to detect renames:

    resolve

    This can only resolve two heads (i.e. the current branch and another branch you pulled from) using a 3-way merge algorithm. It tries to carefully detect criss-cross merge ambiguities. It does not handle renames.

    Also, have you tried looking at similar questions here:

    git rename/delete confusion

    git divergent renaming