Subject: Re: Proper tracking of copies in git log and others

From: Michael J Gruber <[email-masked]>
Date: Tue, 07 Jul 2009 15:48:52 +0200

Lasse Kärkkäinen venit, vidit, dixit 04.07.2009 18:24:
> Getting full history of a file, including that beyond copies, is rather 
> important and apparently not currently supported by git tools.
> 
> An example use case:
> 
> # Create repository
> mkdir courses
> cd courses
> git init
> # Course 2007
> mkdir -p 2007/exercise1
> echo Hello > 2007/exercise1/description.txt
> mkdir 2007/exercise2
> echo World > 2007/exercise2/description.txt
> git add 2007
> git commit -m "Course 2007"
> # Course 2008
> mkdir -p 2008/exercise1
> echo New one > 2008/exercise1/description.txt
> git add 2008
> git commit -m "Course 2008 exercise 1 (new)"
> cp -R 2007/exercise1 2008/exercise2
> git add 2008/exercise2
> git commit -a -m "Course 2008 exercise 2 (from 2007 exercise 1)"
> # Course 2009
> cp -R 2008 2009
> git add 2009
> git commit -m "Course 2009 recycled entirely from 2008"
> 
> Now, if we do git log --follow 2009/exercise2/description.txt or 
> 2009/exercise2, it only prints the "Course 2009" commit instead of the 
> full history because --follow doesn't follow copies. What we actually 
> want is:
> 
> commit 9e17341497b29735bc55b6631b43db6e2f50ed30
> Author: Lasse Karkkainen <[email-masked]>
> Date:   Sat Jul 4 19:05:57 2009 +0300
> 
>      Course 2009 recycled entirely from 2008
> 
> commit 8fd13a8667f0bc5c4851b366864a207fa85519bc
> Author: Lasse Karkkainen <[email-masked]>
> Date:   Sat Jul 4 19:05:57 2009 +0300
> 
>      Course 2008 exercise 2 (from 2007 exercise 1)
> 
> commit 593346660872ada80ba751688fffc7af7a31e124
> Author: Lasse Karkkainen <[email-masked]>
> Date:   Sat Jul 4 19:05:57 2009 +0300
> 
>      Course 2007
> 
> Note: the "Course 2008 exercise 1 (new)" commit is not listed, as it is 
> unrelated to 2009/exercise2.
> 
> Some nice people from #git suggested various commands that would find 
> the previous version (e.g. 2008/exercise2) etc, but none of those got 
> even close to getting this full history over multiple copies, with log 
> messages.
> 
> It would be useful if the git tools could produce history like this with 
> all the tools (log, blame, gitk, etc), preferably with proper branching 
> guesses (guesses because there is no info on where the copy came from), 
> but even a linear history (sorted by commit time?) would do much better 
> than not having anything.

While there is a pending patch as Sean pointed out it still has issues.
For moves, "there is always only one", for copies there are at least
two. So which one do you follow?

If you want to know where the current contents of
2009/exercise2/description.txt come from then a simpler approach may be

git log -S$(git show HEAD:2009/exercise2/description.txt)

This gives you three commits. Guess which ones ;)

Michael