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

Re: Proposal: tell git a file has been renamed

From
JMJeremy Morton <admin@game-point.net>
Date
Apr 24, 2023, 10:10 UTC
Message-ID
<74a361fd-4ee6-f362-8d49-92417f0e2dac@game-point.net>
In-Reply-To
<CAPx1Gvdc6bqzt2PpqD1Z4e5w+b=8gZhUSyfUQC1n8QazdBacEw@mail.gmail.com>
On 24/04/2023 02:43, Chris Torek wrote:>> [renames are a problem]
Show 24 quoted lines
> 
> I have long wondered if there was a way to improve this
> experience myself.
> 
> (I also note that most of the followup messages up to this point
> have missed the point.  It's true that you can run `git mv` and
> `git commit`, but you've already said that this becomes
> particularly painful when you realize that it's appropriate *after
> the fact*, when you've already made intermediate commits and/or
> staged changes or whatever.)
> 
> The index *currently* has no room to store anything like this: it
> is, in effect, just the proposed next commit, stored as a
> flattened tree.  There are, however, extra marker records that
> can be added.  So:
> 
> If `git mv` (or a new command) had a flag to say "make a special
> index entry so that the next `git commit` does a double commit",
> we could in fact make this work.  Alternatively, we could have a
> command -- similar to `git commit --only` in effect -- that uses
> the current (HEAD) commit to construct a renames-only commit, in
> which 100%-identical-file matching would (in general) find the
> desired renames -- and make it, perhaps also co-ordinating with
> `git mv` of existing files in the index.  (I'd also like to have

I'm not sure what the utility of the --only thing would be - to detect renames that didn't have changed content so that all renames could be done in one pre-commit?

> `git mv --after`, in the same vein as `hg mv --after`; I long ago
> wrote a cheesy script to achieve this, but it would be nice to
> have a proper command.)

Huh, I just read the docs on that... does that mean hg already has this functionality of being able to store a "this was renamed" marker in its index?

Show 10 quoted lines
> On top of this, it might be nice to have a standardized commit
> message and/or other marker (in the commit header?) for a "rename-
> only" commit, which this kind of extra-rename-commit operation
> would use.  Then `git log` and `git blame` and other commands
> could easily detect such commits and default to an automatic
> `--follow` style following, and `git log` might be allowed to omit
> the *display* of such a commit by default, by showing all the
> renames as renames in the subsequent commit (though this would
> presumably require an internal verification step to check for
> spoofed renames that are not in fact rename-only operations).

I'm surprised --follow isn't the default, actually... isn't the whole point of detecting renames to allow content history to be tracked back through renames?

Another one that jumped to mind for me is bisect. As rename-only commits are liable to create broken builds, it should skip over them to the 'content' commit.

> In any case, this *idea* is easy, like many ideas.  It really
> comes down to implementation.  If someone thinks this is a great
> idea, someone (perhaps me) should work on *implementing* it. :-)

If you do please feel free to CC me in an email about it, it'd be good to know if this became available!

-- 
Best regards,
Jeremy Morton (Jez)
Previous: Chris TorekNext: Chris Torek
Message 10 of 24 in “Proposal: tell git a file has been renamed”
  1. Jeremy MortonApr 22, 2023
  2. rsbecker@nexbridge.comApr 22, 2023
  3. Jeremy MortonApr 22, 2023
  4. rsbecker@nexbridge.comApr 22, 2023
  5. Jeremy MortonApr 22, 2023
  6. rsbecker@nexbridge.comApr 22, 2023
  7. Erik Cervin EdinApr 23, 2023
  8. Kristoffer HaugsbakkApr 23, 2023
  9. Chris TorekApr 24, 2023
  10. Jeremy MortonApr 24, 2023
  11. Chris TorekApr 24, 2023
  12. Erik Cervin EdinApr 24, 2023
  13. Jeremy MortonApr 24, 2023
  14. Erik Cervin EdinApr 24, 2023
  15. Jeremy MortonApr 24, 2023
  16. Felipe ContrerasApr 24, 2023
  17. Jacob KellerApr 24, 2023
  18. Felipe ContrerasApr 24, 2023
  19. Jacob KellerApr 26, 2023
  20. Junio C HamanoApr 26, 2023
  21. Erik Cervin EdinMay 11, 2023
  22. Junio C HamanoApr 24, 2023
  23. Junio C HamanoApr 24, 2023
  24. Jeremy MortonApr 24, 2023

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.