* weird behaviour in git
@ 2015-02-26 14:12 Thomas Klausner
2015-02-26 14:45 ` Michael J Gruber
2015-02-26 15:54 ` David Kastrup
0 siblings, 2 replies; 5+ messages in thread
From: Thomas Klausner @ 2015-02-26 14:12 UTC (permalink / raw)
To: git
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: weird behaviour in git
2015-02-26 14:12 weird behaviour in git Thomas Klausner
@ 2015-02-26 14:45 ` Michael J Gruber
2015-02-26 14:58 ` Thomas Klausner
2015-02-26 15:54 ` David Kastrup
1 sibling, 1 reply; 5+ messages in thread
From: Michael J Gruber @ 2015-02-26 14:45 UTC (permalink / raw)
To: Thomas Klausner, git
Thomas Klausner venit, vidit, dixit 26.02.2015 15:12:
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: weird behaviour in git
2015-02-26 14:45 ` Michael J Gruber
@ 2015-02-26 14:58 ` Thomas Klausner
2015-02-26 15:22 ` Michael J Gruber
0 siblings, 1 reply; 5+ messages in thread
From: Thomas Klausner @ 2015-02-26 14:58 UTC (permalink / raw)
To: Michael J Gruber; +Cc: git
On Thu, Feb 26, 2015 at 03:45:13PM +0100, Michael J Gruber wrote:
> Thomas Klausner venit, vidit, dixit 26.02.2015 15:12:
> > 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 ;)
Sure, that's one way to look at it, but I disagree. You give the user
the way to tell the system the intention of which file moves where,
but internally this information is lost and "guessed" incorrectly.
hg seems to do this correctly, the same commands with 'hg diff --git'
at the end show:
diff --git a/Makefile b/Makefile
new file mode 100644
diff --git a/a b/b
rename from a
rename to b
Thomas
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: weird behaviour in git
2015-02-26 14:58 ` Thomas Klausner
@ 2015-02-26 15:22 ` Michael J Gruber
0 siblings, 0 replies; 5+ messages in thread
From: Michael J Gruber @ 2015-02-26 15:22 UTC (permalink / raw)
To: Thomas Klausner; +Cc: git
Thomas Klausner venit, vidit, dixit 26.02.2015 15:58:
> On Thu, Feb 26, 2015 at 03:45:13PM +0100, Michael J Gruber wrote:
>> Thomas Klausner venit, vidit, dixit 26.02.2015 15:12:
>>> 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 ;)
>
> Sure, that's one way to look at it, but I disagree. You give the user
> the way to tell the system the intention of which file moves where,
> but internally this information is lost and "guessed" incorrectly.
>
> hg seems to do this correctly, the same commands with 'hg diff --git'
> at the end show:
>
> diff --git a/Makefile b/Makefile
> new file mode 100644
> diff --git a/a b/b
> rename from a
> rename to b
>
> Thomas
>
Maybe you can re-read what I wrote above, keeping in mind the first line:
git tracks content, not paths.
That explains everything, really.
Michael
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: weird behaviour in git
2015-02-26 14:12 weird behaviour in git Thomas Klausner
2015-02-26 14:45 ` Michael J Gruber
@ 2015-02-26 15:54 ` David Kastrup
1 sibling, 0 replies; 5+ messages in thread
From: David Kastrup @ 2015-02-26 15:54 UTC (permalink / raw)
To: Thomas Klausner; +Cc: git
Thomas Klausner <tk@giga.or.at> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-02-26 15:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-26 14:12 weird behaviour in git Thomas Klausner
2015-02-26 14:45 ` Michael J Gruber
2015-02-26 14:58 ` Thomas Klausner
2015-02-26 15:22 ` Michael J Gruber
2015-02-26 15:54 ` David Kastrup
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).