Subject: Re: weird behaviour in git

From: David Kastrup <[email-masked]>
Date: Thu, 26 Feb 2015 16:54:30 +0100

Thomas Klausner <[email-masked]> writes:

> 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
> #

git mv was tasked with removing file a and creating file b with the same
content and permissions.  It did so successfully.

"Changes to be committed" states an interpretation consistent with that.

Now it is entirely silly in my book to describe files as "renamed" that
are actually empty and thus do not contain a single common byte.
I would call that change description a bug or at least a "misfeature".

git mv, however, did exactly what it was tasked to do and could not
possibly do anything better since Git does, by design, not ever track
file operations.

> 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.

No.  Git mv is just a convenience command for deleting one file and
creating another one with the same contents.  Git has no concept of file
renames in its repository, so git mv cannot record anything there that
could not be interpreted exactly like the commit info interpreted it.

It's nonsensical and should in my opinion rather be stated as

# Changes to be committed:
#       removed:    a
#       new file:   Makefile
#       new file:   b

But that's not the fault of Git mv.

-- 
David Kastrup