threads / discuss / 22477

A git-mv question

Subject: A git-mv question

## tl;dr

5 messages between Feb 2, 2010 and Feb 2, 2010.

replies: 4people: 4as markdown or json

Ron Garret· Feb 2, 2010, 00:08 UTC · lore

If I do a git-mv *and* edit the file all in one commit, does that get recorded in a way that allows git to track the change through the changed file name? In other words, if I do just a git-mv (without changing the file) git can track that by observing that two differently named objects in two different commit trees contain the same blob. But if the file is edited then the blobs will be different. Is git smart enough to distinguish a git-mv and edit from, say, the equivalent git-rm and git-add? If so, how does it do it?

Thanks, rg

Nicolas Pitre· Feb 2, 2010, 00:29 UTC · re: Ron Garret · lore

Re: A git-mv question

On Mon, 1 Feb 2010, Ron Garret wrote:
Show 8 quoted lines
> If I do a git-mv *and* edit the file all in one commit, does that get 
> recorded in a way that allows git to track the change through the 
> changed file name?  In other words, if I do just a git-mv (without 
> changing the file) git can track that by observing that two differently 
> named objects in two different commit trees contain the same blob.  But 
> if the file is edited then the blobs will be different.  Is git smart 
> enough to distinguish a git-mv and edit from, say, the equivalent git-rm 
> and git-add?  If so, how does it do it?
Please see:
http://www.kernel.org/pub/software/scm/git/docs/gitdiffcore.html
Nicolas
Junio C Hamano· Feb 2, 2010, 00:46 UTC · re: Nicolas Pitre · lore

Re: A git-mv question

Nicolas Pitre <nico@fluxnic.net> writes:
> Please see:
>
> http://www.kernel.org/pub/software/scm/git/docs/gitdiffcore.html
Thanks.
Probably it needs a bit of updates to help new people read it.
 * It talks about diff-* family.  They exist, but what they do can be
   triggered also by "diff" wrapper and that is the primary way the users
   know about "diff" these days.
 * Because it was written to illustrate the low-level diff-* family, it
   says "when they are run without -p option".  People who only know
   Porcelain "diff" need to read as if it said "when run with --raw".
 * It does not talk about "log -p" but the discussion applies there as
   well (log is a glorified form of diff-tree).
Ron Garret· Feb 2, 2010, 07:21 UTC · re: Nicolas Pitre · lore

Re: A git-mv question

In article <alpine.LFD.2.00.1002011927490.1681@xanadu.home>,
 Nicolas Pitre <nico@fluxnic.net> wrote:
Show 15 quoted lines
> On Mon, 1 Feb 2010, Ron Garret wrote:
> 
> > If I do a git-mv *and* edit the file all in one commit, does that get 
> > recorded in a way that allows git to track the change through the 
> > changed file name?  In other words, if I do just a git-mv (without 
> > changing the file) git can track that by observing that two differently 
> > named objects in two different commit trees contain the same blob.  But 
> > if the file is edited then the blobs will be different.  Is git smart 
> > enough to distinguish a git-mv and edit from, say, the equivalent git-rm 
> > and git-add?  If so, how does it do it?
> 
> Please see:
> 
> http://www.kernel.org/pub/software/scm/git/docs/gitdiffcore.html
> 
Thanks!  A little light reading :-)
rg
Jakub Narebski· Feb 2, 2010, 15:32 UTC · re: Ron Garret · lore

Re: A git-mv question

Ron Garret <ron1@flownet.com> writes:
Show 8 quoted lines
> If I do a git-mv *and* edit the file all in one commit, does that get 
> recorded in a way that allows git to track the change through the 
> changed file name?  In other words, if I do just a git-mv (without 
> changing the file) git can track that by observing that two differently 
> named objects in two different commit trees contain the same blob.  But 
> if the file is edited then the blobs will be different.  Is git smart 
> enough to distinguish a git-mv and edit from, say, the equivalent git-rm 
> and git-add?  If so, how does it do it?

Git does not distinguish between git-mv and equivalent git-rm+git-add; it employs heuristic similarity based (based on how contents of files is similar to each other) rename detection.

Also worth noting is that git does consider only endpoints for rename detection in diff and in merge; it does not check history if there were clean rename / rename + edit.

-- 
Jakub Narebski
Poland
ShadeHawk on #git

← back to recent threads