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

Re: weird behaviour in git

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Feb 26, 2015, 14:45 UTC
Message-ID
<54EF3179.8030104@drmicha.warpmail.net>
In-Reply-To
<20150226141234.GP19896@danbala.tuwien.ac.at>
Thomas Klausner venit, vidit, dixit 26.02.2015 15:12:
Show 37 quoted lines
> Hi!
> 
> I've played around with git and found that 'git mv' does not honor
> what I tell it to do:
> 
> wiz@yt:~> mkdir a
> wiz@yt:~> cd a
> wiz@yt:~/a> git init .
> Initialized empty Git repository in /home/wiz/a/.git/
> wiz@yt:~/a> touch a
> wiz@yt:~/a> git add a
> wiz@yt:~/a> git commit -m 'add a'
> [master (root-commit) 99d0ee7] add a
>  1 file changed, 0 insertions(+), 0 deletions(-)
>  create mode 100644 a
> wiz@yt:~/a> git mv a b
> wiz@yt:~/a> touch Makefile
> wiz@yt:~/a> git add Makefile
> wiz@yt:~/a> git commit
> 
> 
> # Please enter the commit message for your changes. Lines starting
> # with '#' will be ignored, and an empty message aborts the commit.
> # On branch master
> # Changes to be committed:
> #       renamed:    a -> Makefile
> #       new file:   b
> #
> 
> This is reproducible for me with "git version 2.3.0" on
> NetBSD-7.99.5/amd64.
> 
> I guess this happens because the checksums of the files are the same
> and 'Makefile' is earlier when sorting, but since I explicitly told
> "git mv" old and new name, I think that's a bug nevertheless.
>  Thomas
> 
git tracks content, not paths.

It does record the path at which the tracked content is, of course. But it tracks the history of content, not that of paths.

What you see in the diff above is merely one way to interpret the history of the content. Saying

renamed: a -> b new file: Makefile

leads to the same content at the same paths (with the proper new file content).

By default, diff tries to interpret content history in terms of renames and copies when possible, in order to help users. Sometimes this fails - while still being correct, it confuses them ;)

Michael
Previous: Thomas KlausnerNext: Thomas Klausner
Message 2 of 5 in “weird behaviour in git”
  1. Thomas KlausnerFeb 26, 2015
  2. Michael J GruberFeb 26, 2015
  3. Thomas KlausnerFeb 26, 2015
  4. Michael J GruberFeb 26, 2015
  5. David KastrupFeb 26, 2015

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.