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

Re: git mv after the fact

From
Chris Torek <chris.torek@gmail.com>
Date
May 27, 2026, 03:19 UTC
Message-ID
<CAPx1GvetxY1T7cuFN_xe51EURr-ED2BqW3E82jj90ko3PSYSyg@mail.gmail.com>
In-Reply-To
<xmqqy0h5lfa0.fsf@gitster.g>
> Chris Torek <chris.torek@gmail.com> writes:
>> A flag for "git mv" would be convenient (and slightly moreefficient ...
>
On Tue, May 26, 2026 at 8:09 PM Junio C Hamano <gitster@pobox.com> wrote:
> May be convenient, but I do not get the "efficient" part.

A normal `git mv` renames the index entry and the file in the working tree without running `git add` on the *contents*, so there's no new hash computation. Presumably a `git mv --after foo bar` would do the same: verify that there is no existing `bar` in the index, that there is an existing `foo` in the index, and that there is no `foo` but there is a `bar` in the working tree, and then it would rename (add-and-remove, really, because of sorting) the index entry, without scanning the working tree contents.

In other words, we skip reading the 3 terabyte file, or whatever.
Anyway, comparing to `git rm --cached`:
> I think the requested "feature" is not all that outrageous.  It
> would be a similar value as a morning-after correction measure for
> "oops, I moved the file in the filesystem without telling Git".

I agree, but I also don't see it as valuable enough to bother writing a proper implementation.

I did write it up as a shell script though, long ago. Adding it here via gmail would mess with white space so I'll just provide a link to the file on GitHub:

https://github.com/chris3torek/scripts/blob/master/git-mv-after
Chris
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 10 in “git mv after the fact”
  1. Frieder HannenheimMay 26, 2026
  2. Chris TorekMay 26, 2026
  3. Frieder HannenheimMay 26, 2026
  4. Ben KnobleMay 26, 2026
  5. Junio C HamanoMay 27, 2026
  6. Chris TorekMay 27, 2026
  7. Junio C HamanoMay 27, 2026
  8. Ben KnobleMay 28, 2026
  9. Junio C HamanoMay 28, 2026
  10. Tim TassonisMay 27, 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.