git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Different behaviour for --find-renames between git diff and git merge?

From
Elijah Newren <newren@gmail.com>
Date
Dec 13, 2025, 01:57 UTC
Message-ID
<CABPp-BH80R4LJDRKQnPmh5Am_HAcCgxWiA8vRoN8LgLRUMz+JQ@mail.gmail.com>
In-Reply-To
<3742e7de-7d88-4e77-b711-9fed867a8c23@gmail.com>

On Fri, Dec 12, 2025 at 10:06 AM Luca Balsanelli <lucabalsanelli@gmail.com> wrote:

Show 5 quoted lines
>
> Hi,
>
>    I'm scratching my head to understand why on the following case `git
> diff` and `git merge` give a different interpretation about a rename.
I don't see any difference...
Show 23 quoted lines
>     git switch master
>     touch aaa
>     git add aaa
>     git commit -m 'aaa'
>
>     git switch -c branch
>     echo -en 'A\nB\nC\n' > aaa
>     git add aaa
>     git commit -m 'A\nB\nC\n > aaa'
>
>     git switch master
>     echo -en 'A\nB\n' > aaa
>     mkdir dir
>     mv aaa dir/
>     git add aaa dir/
>     git commit -m 'A\nB\n > aaa -> dir/'
>
> The `|merge.renames` config variable is true. Changing `git diff
> --find-renames=50%` (the default) or `git merge -s ort -X
> find-renames=50%` ||to something lower does not change the following.
> |
>
> `git diff` prints
Actually, it doesn't; more on that below...
>
>     diff --git a/aaa b/dir/aaa
>     similarity index 71%

Did you not follow your own recipe? Maybe you inserted an extra space or left off the 'n' in 'echo -en' when you ran this? The number should have been 66%.

Show 11 quoted lines
>     rename from aaa
>     rename to dir/aaa
>     index bbd2b90..986ad36 100644
>     --- a/aaa
>     +++ b/dir/aaa
>     @@ -1,4 +1,3 @@
>       A
>       B
>     -C
>
>      that is the similarity index is 71% and it detects the rename.
At this point, if you actually run `git diff` you see the following:

$ git diff $

i.e. nothing. I suspect you gave `git diff` additional arguments but didn't tell us. Let's look at a few options:

$ git diff master~1 master
diff --git a/aaa b/aaa
deleted file mode 100644
index e69de29..0000000
diff --git a/dir/aaa b/dir/aaa
new file mode 100644
index 0000000..35d242b
--- /dev/null
+++ b/dir/aaa
@@ -0,0 +1,2 @@
+A
+B
$

So, on master, aaa was deleted, and dir/aaa was added.

$ git diff master~1 branch
diff --git a/aaa b/aaa
index e69de29..b1e6722 100644
--- a/aaa
+++ b/aaa
@@ -0,0 +1,3 @@
+A
+B
+C
$

On branch, aaa was modified.

$ git diff branch master
diff --git a/aaa b/dir/aaa
similarity index 66%
rename from aaa
rename to dir/aaa
index b1e6722..35d242b 100644
--- a/aaa
+++ b/dir/aaa
@@ -1,3 +1,2 @@
 A
 B
-C
$

So, only if you diff the endpoints of the two branches do you see a
rename; if you look from the merge base to either branch, there isn't
one.

> `git merge branch`, instead, gives
>
>     CONFLICT (modify/delete): aaa deleted in HEAD and modified in
>     branch.  Version branch of aaa left in tree.
>     Automatic merge failed; fix conflicts and then commit the result

Yes, this exactly matches what diff showed above -- on HEAD (master),
'aaa' was deleted, and on branch, 'aaa' was modified.

> Why it is that? I always supposed that the rename detection was the same
> for `git diff`, `git merge`. Reading the documentation I do not find any
> hint why `git diff` and `git merge` are behaving differently.

Hope that helps...
Previous: Luca BalsanelliNext: Luca Balsanelli
Message 2 of 6 in “Different behaviour for --find-renames between git diff and git merge?”
  1. Luca BalsanelliDec 12, 2025
  2. Elijah NewrenDec 13, 2025
  3. Luca BalsanelliDec 15, 2025
  4. Elijah NewrenDec 16, 2025
  5. Luca BalsanelliDec 16, 2025
  6. Elijah NewrenDec 16, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.