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

Re: git rename/moved status unreliable in ruby

From
Ssebastien.stettler <sebastien.stettler@proton.me>
Date
May 2, 2026, 09:34 UTC
Message-ID
<IC7a4NnSKMdvXlVyaSDYEtU7iRlKdJGzCwrXNCFKrtFfnBJTMrwY522rHF8PfzYxFs43huo0KFGrqB6f4IQjmvYi2B8Ehh0cwfjHHOYW_RU=@proton.me>
In-Reply-To
<CAPx1Gvd_VEWHrBWtUjNeWZ+wfmsAOTamKmL6fhBSQi=MbmXRcw@mail.gmail.com>
Thanks for all the responses and thoughts thus far.
> Which means that git sees that every line has changed because the
> indentation has changed. If you want git to realize that the file has
> been renamed you could move it in one commit and then add modify it in
> the next commit.

This is the minimal solution to the problem but as Johannes illustrated, there cases where that "move commit doesn't solve the problem"

Show 5 quoted lines
> Splitting into two commits helps only certain
> cases, in particular, when the commit that moves the files is compared
> to an earlier commit, such as `git log` does. However, if a commit after
> the change is compared to a commit before the move, the rename is still
> not detected.
Further examples:

The move commit helps if i want to blame a file if i use the -W option, but if it doesnt help with git log since the changes are now considered modifications.

git blame -w ruby-example/lib/calculator.rb (shows previous files changes and not the indentation) ``` 303f25f5 ruby-example/lib/calculator.rb (nothing 2026-05-02 16:40:51 +0800 1) module Lib ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 2) class Calculator ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 3) def add(a, b) 3d22d303 ruby-example/calculator.rb (billybonks 2026-05-02 16:34:14 +0800 4) a + b ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 5) end ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 6) ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 7) def subtract(a, b) ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 8) a - b ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 9) end ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 10) ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 11) def multiply(a, b) ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 12) a * b ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 13) end ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 14) ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 15) def divide(a, b) ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 16) raise ZeroDivisionError, 'Cannot divide by zero' if b.zero? ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 17) ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 18) a / b ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 19) end ^1cf274f ruby-example/calculator.rb (billybonks 2026-05-01 12:36:47 +0800 20) end 303f25f5 ruby-example/lib/calculator.rb (nothing 2026-05-02 16:40:51 +0800 21) end ```

git log --follow --diff-filter=ra -- ruby-example/lib/calculator.rb
( it does not show the move commit )
```
commit 303f25f50cde83c46f83bc3c337cd52b87b63d52 (HEAD -> example-2)
Author: nothing <nothing@contributed.com>
Date:   Sat May 2 16:40:51 2026 +0800
    update lib and require
commit 3d22d30304d836c07b3274689e5e2c536b29e1bb (example-3)
Author: billybonks <sebastienstettler@gmail.com>
Date:   Sat May 2 16:34:14 2026 +0800
    fix: sum was doing subtraction instead of addition
```
Using this approach does incur a heavy burnder on the user since most tools that do renaming etc 
will move and rename, and that cost does not give a complete solution as there are still many thigns
that don't work in the most ideal sense.
As mentioned by Chris
Show 6 quoted lines
> It *could* be improved. Doing so in a way that works for more than
> just some special cases -- e.g., in a way that works for ordinary
> text, or graphical images, for instance, rather than just for Ruby
> sources (or just C sources, or C++, or Swift, or Python, or whatever)
> -- seems particularly tricky. Some degree of ignoring white-space
> changes would probably help multiple cases, though.
Has there been explorations of ignoring white space for the similarity checker, i would 
assume that majority of white space movements across many languages would result in a 
semantically similar document in most cases.
 
- Sebastien
Previous: Chris TorekNext: Jeff King
Message 6 of 9 in “git rename/moved status unreliable in ruby”
  1. sebastien.stettlerMay 1, 2026
  2. Phillip WoodMay 1, 2026
  3. Johannes SixtMay 2, 2026
  4. Junio C HamanoMay 3, 2026
  5. Chris TorekMay 2, 2026
  6. sebastien.stettlerMay 2, 2026
  7. Jeff KingMay 4, 2026
  8. Junio C HamanoMay 5, 2026
  9. Chris TorekMay 5, 2026

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.