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

Re: Rename handling

From
Steven Grimm <koreth@midwinter.com>
Date
Mar 19, 2007, 18:14 UTC
Message-ID
<45FED31B.8070307@midwinter.com>
In-Reply-To
<slrnevtdfh.v0v.jgoerzen@katherina.lan.complete.org>
John Goerzen wrote:
Show 6 quoted lines
> 2) For me, a rename is a logical change to the source tree that I want
>    to be recorded with absolute certainty, not guessed about later.
>    Sometimes I may make API changes and it is useful to see how module
>    names changed, with complete precision, later.  I do not want to be
>    victim to an incorrect guess, which could be possible.
>   

If you commit your renames separately from your content changes, it'll be unambiguous and you won't have to worry about it. That's what I usually do when this is a concern and it has yet to break for me.

On the other hand, I agree with your general point; I really don't like being uncertain about whether renames are going to come out correctly or not ("it has always worked before" and "it is by design unable to fail" are two very different things.) In particular, I strongly disagree with the "names are just syntactic sugar, it's the content we're tracking" philosophy. Here's a simple example of why:

#include <xyz.h>

That simple statement is an intermingling of content and namespace. The presence of something like that actually breaks the "commit the rename separately" approach -- if you rename xyz.h to something else and commit just that rename, that revision won't compile, and I *really* don't like intentionally committing broken revisions.

Okay, so you say, rename xyz.h and update the references to it, but don't actually modify it. Fine, that works in this case. Now how about this one:

public abstract class Foo {
    private static Logger logger = Logger.getLogger(Foo.class.getName());
}

The references to the name "Foo.java" in that case are within the file itself (assuming you're using a Java compiler that requires the filename and class name to match, which the common ones do.) You can't change just the references without changing the file you're renaming. And, depending on how many self-references there are in this file, it's anyone's guess whether the content-based rename detection will consider the renamed file to be close enough to the old one to be a probable rename.

Combine renames with major code refactoring where the content changes substantially, and all bets are off.

Now, having said all that, I'll argue in favor of the content-based rename support for a moment. It is extremely cool that git will actually detect renames in third-party packages where you've just untarred a new release into your git repository and committed it, but have given git no hints at all about the nature of the content changes. I'm not aware of any other version control system that'll do that, and I've taken advantage of that feature in the past. So by no stretch am I saying that content-based rename detection is worthless.

But I would sure rest a lot easier if "git mv" would record a "the user renamed this file" entry in some log somewhere and the merge code would see that entry and say, "aha, no need to guess at it, file X got renamed to Y." Bonus points if that record could apply to directories too, so you don't have the "I created a new file in a directory you renamed, and after git-pull my file is still sitting by itself in the old directory" bug. If no such record exists, then the current rename code should still be invoked to work its considerable magic.

So to answer your question, in my opinion if 100% guaranteed renames are high on your priority list, then Mercurial might be the better option for now. In practice, I've found that git's 99+% rename detection has yet to fail on me aside from the above directory renaming case, but at the end of the day it *is* guessing at your renames after the fact.

Okay, git gurus, show me no mercy. :)
-Steve
Previous: John GoerzenNext: Nicolas Pitre
Message 2 of 31 in “Rename handling”
  1. John GoerzenMar 19, 2007
  2. Steven GrimmMar 19, 2007
  3. Nicolas PitreMar 19, 2007
  4. Linus TorvaldsMar 19, 2007
  5. Steven GrimmMar 19, 2007
  6. Martin LanghoffMar 19, 2007
  7. Junio C HamanoMar 20, 2007
  8. Linus TorvaldsMar 19, 2007
  9. Robin RosenbergMar 19, 2007
  10. Linus TorvaldsMar 19, 2007
  11. Steven GrimmMar 19, 2007
  12. Steven GrimmMar 19, 2007
  13. Linus TorvaldsMar 19, 2007
  14. Nicolas PitreMar 19, 2007
  15. Daniel BarkalowMar 19, 2007
  16. Andy ParkinsMar 19, 2007
  17. Steven GrimmMar 19, 2007
  18. Jakub NarebskiMar 21, 2007
  19. Johannes SchindelinMar 21, 2007
  20. Steven GrimmMar 21, 2007
  21. Johannes SchindelinMar 21, 2007
  22. Linus TorvaldsMar 21, 2007
  23. Martin LanghoffMar 22, 2007
  24. Jakub NarebskiMar 22, 2007
  25. Martin LanghoffMar 22, 2007
  26. Jakub NarebskiMar 22, 2007
  27. Linus TorvaldsMar 22, 2007
  28. Daniel BarkalowMar 19, 2007
  29. John GoerzenMar 19, 2007
  30. Junio C HamanoMar 19, 2007
  31. Jakub NarebskiMar 21, 2007

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.