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

diff.renames not working?

From
RDRobert Dailey <rcdailey.lists@gmail.com>
Date
Sep 13, 2019, 20:24 UTC
Message-ID
<CAHd499BT35jvPtsuD9gfJB0HJ=NxtzyQOaiD7-=sHJbFYhphpg@mail.gmail.com>

I'm using Git version 2.23. I have the `diff.renames` setting set to `copies`. My code base has a file named `JniPaymentManager.hpp` (and `cpp`) that had too much code in it, so I refactored this file by splitting out a significant portion of the code in it to another file, named `ZPayClient.hpp` (and `cpp`). When I diff the topic branch against the mainline, it shows it as a copy with a percentage:

``` $ git diff --name-status master...topic C055 Jni/JniPaymentManager.cpp ZPay/ZPayClient.cpp C070 Jni/JniPaymentManager.hpp ZPay/ZPayClient.hpp ```

Now my goal is to diff `ZPayClient.hpp` and see the changes to the moved-out portion of code as it relates to the original state of that code in `JniPaymentManager.hpp`. To do this, I tried this command:

``` $ git diff master...topic -- ZPay/ZPayClient.hpp ```

The unified diff header I got back is:
```
diff --git ZPay/ZPayClient.hpp ZPay/ZPayClient.hpp
new file mode 100644
index 00000000..6ebc2a9a
--- /dev/null
+++ ZPay/ZPayClient.hpp
```

Hmm, it's treating it as a new file. Even though I have `diff.renames`
set to `copies`? Even though `diff --name-status` acknowledges the
relationship with the original file for the code on `master`? This is
confusing...

Out of curiosity, I thought I'd try this command:

```
git diff --follow master...topic -- ZPay/ZPayClient.hpp
```

And I get this unified diff header:

```
diff --git Jni/JniPaymentManager.hpp ZPay/ZPayClient.hpp
similarity index 70%
copy from Jni/JniPaymentManager.hpp
copy to ZPay/ZPayClient.hpp
index fc18e2d2..6ebc2a9a 100644
--- Jni/JniPaymentManager.hpp
+++ ZPay/ZPayClient.hpp
```

Now this looks more like it. I can actually see a useful diff here,
instead of everything looking like a new file. But there is a lot of
confusion here:

1. `diff --follow` is not a documented[1] option. Why does it work?
2. `diff -M` doesn't actually work either. It should, though. In fact,
I expected it to work as `--follow` does. But it doesn't.
3. The `diff.renames` config doesn't seem to be working here, when it should.

Can someone explain the behavior I'm seeing? I really am confused
about all this...

[1]: https://git-scm.com/docs/git-diff
Next: Bryan Turner
Message 1 of 5 in “diff.renames not working?”
  1. Robert DaileySep 13, 2019
  2. Bryan TurnerSep 13, 2019
  3. Jeff KingSep 14, 2019
  4. Robert DaileySep 16, 2019
  5. Junio C HamanoSep 16, 2019

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.