* Which file is older in history?
@ 2013-03-20 20:21 Ramkumar Ramachandra
2013-03-20 20:46 ` Junio C Hamano
0 siblings, 1 reply; 7+ messages in thread
From: Ramkumar Ramachandra @ 2013-03-20 20:21 UTC (permalink / raw)
To: Git List
Hi,
I want to compare two files in a git repository and tell which one was
introduced into the repository earlier, assuming that they're in the
same history line (by ancestry, not timestamp). The naive way to do
this is to find the individual commits that introduced the files
(`rev-list HEAD -- <filename> | tail -n 1`), and query whether there
are commits between them (`rev-list commit1 ^commit2`). However, this
is slow. What about bisecting the history until we find a tree that
contains one file but not the other?
Thanks.
Ram
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Which file is older in history?
2013-03-20 20:21 Which file is older in history? Ramkumar Ramachandra
@ 2013-03-20 20:46 ` Junio C Hamano
2013-03-21 11:59 ` Ramkumar Ramachandra
0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2013-03-20 20:46 UTC (permalink / raw)
To: Ramkumar Ramachandra; +Cc: Git List
Ramkumar Ramachandra <artagnon@gmail.com> writes:
> I want to compare two files in a git repository and tell which one was
> introduced into the repository earlier, assuming that they're in the
> same history line (by ancestry, not timestamp). The naive way to do
> this is to find the individual commits that introduced the files
> (`rev-list HEAD -- <filename> | tail -n 1`), and...
This must be a trick question but the naïve way I think of is
git log --diff-filter=A -- path1 path2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Which file is older in history?
2013-03-20 20:46 ` Junio C Hamano
@ 2013-03-21 11:59 ` Ramkumar Ramachandra
2013-03-21 12:21 ` Jeff King
0 siblings, 1 reply; 7+ messages in thread
From: Ramkumar Ramachandra @ 2013-03-21 11:59 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git List
Junio C Hamano wrote:
> Ramkumar Ramachandra <artagnon@gmail.com> writes:
>
>> I want to compare two files in a git repository and tell which one was
>> introduced into the repository earlier, assuming that they're in the
>> same history line (by ancestry, not timestamp). The naive way to do
>> this is to find the individual commits that introduced the files
>> (`rev-list HEAD -- <filename> | tail -n 1`), and...
>
> This must be a trick question but the naïve way I think of is
>
> git log --diff-filter=A -- path1 path2
Thanks, I didn't know about --diff-filter. I'll need one extra step
to figure out which commit corresponds to the introduction of which
file, no?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Which file is older in history?
2013-03-21 11:59 ` Ramkumar Ramachandra
@ 2013-03-21 12:21 ` Jeff King
2013-03-21 12:24 ` Jeff King
0 siblings, 1 reply; 7+ messages in thread
From: Jeff King @ 2013-03-21 12:21 UTC (permalink / raw)
To: Ramkumar Ramachandra; +Cc: Junio C Hamano, Git List
On Thu, Mar 21, 2013 at 05:29:39PM +0530, Ramkumar Ramachandra wrote:
> > This must be a trick question but the naïve way I think of is
> >
> > git log --diff-filter=A -- path1 path2
>
> Thanks, I didn't know about --diff-filter. I'll need one extra step
> to figure out which commit corresponds to the introduction of which
> file, no?
Maybe
git log --format=%H --name-status --diff-filter=A -- path1 path2 |
perl -lne '
if (/[0-9a-f]{40}/) { $commit = $& }
elsif (/^A\t(.*)/) { $h{$1} = $commit }
END { print "$h{$_} $_" for keys(%h) }
'
?
-Peff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Which file is older in history?
2013-03-21 12:21 ` Jeff King
@ 2013-03-21 12:24 ` Jeff King
2013-03-21 12:32 ` Ramkumar Ramachandra
0 siblings, 1 reply; 7+ messages in thread
From: Jeff King @ 2013-03-21 12:24 UTC (permalink / raw)
To: Ramkumar Ramachandra; +Cc: Junio C Hamano, Git List
On Thu, Mar 21, 2013 at 08:21:30AM -0400, Jeff King wrote:
> On Thu, Mar 21, 2013 at 05:29:39PM +0530, Ramkumar Ramachandra wrote:
>
> > > This must be a trick question but the naïve way I think of is
> > >
> > > git log --diff-filter=A -- path1 path2
> >
> > Thanks, I didn't know about --diff-filter. I'll need one extra step
> > to figure out which commit corresponds to the introduction of which
> > file, no?
>
> Maybe
>
> git log --format=%H --name-status --diff-filter=A -- path1 path2 |
> perl -lne '
> if (/[0-9a-f]{40}/) { $commit = $& }
> elsif (/^A\t(.*)/) { $h{$1} = $commit }
> END { print "$h{$_} $_" for keys(%h) }
> '
Actually, I only looked at your question, not the original point, which
was not which commit was which, but which one was older. If you just
want to know which is older, then just:
git log --format=%H --name-status --diff-filter=A -- path1 path2 |
grep ^A |
tail -1
which uses the regular traversal order (i.e., mostly following commit
timestamps). You can use --topo-order if you want to make sure it
follows the graph structure.
-Peff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Which file is older in history?
2013-03-21 12:24 ` Jeff King
@ 2013-03-21 12:32 ` Ramkumar Ramachandra
2013-03-21 13:26 ` Jeff King
0 siblings, 1 reply; 7+ messages in thread
From: Ramkumar Ramachandra @ 2013-03-21 12:32 UTC (permalink / raw)
To: Jeff King; +Cc: Junio C Hamano, Git List
Jeff King wrote:
> On Thu, Mar 21, 2013 at 08:21:30AM -0400, Jeff King wrote:
>
>> On Thu, Mar 21, 2013 at 05:29:39PM +0530, Ramkumar Ramachandra wrote:
>>
>> > > This must be a trick question but the naïve way I think of is
>> > >
>> > > git log --diff-filter=A -- path1 path2
>> >
>> > Thanks, I didn't know about --diff-filter. I'll need one extra step
>> > to figure out which commit corresponds to the introduction of which
>> > file, no?
>>
>> Maybe
>>
>> git log --format=%H --name-status --diff-filter=A -- path1 path2 |
>> perl -lne '
>> if (/[0-9a-f]{40}/) { $commit = $& }
>> elsif (/^A\t(.*)/) { $h{$1} = $commit }
>> END { print "$h{$_} $_" for keys(%h) }
>> '
>
> Actually, I only looked at your question, not the original point, which
> was not which commit was which, but which one was older. If you just
> want to know which is older, then just:
>
> git log --format=%H --name-status --diff-filter=A -- path1 path2 |
> grep ^A |
> tail -1
Great! I just learnt about --name-status now.
Nit: tail -<n> is deprecated in favor of tail -n <n>, I think. It's
nicer to have definite fixed command line options, as opposed to
parsing an arbitrary -(*) and deciding if \1 is a \d+.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Which file is older in history?
2013-03-21 12:32 ` Ramkumar Ramachandra
@ 2013-03-21 13:26 ` Jeff King
0 siblings, 0 replies; 7+ messages in thread
From: Jeff King @ 2013-03-21 13:26 UTC (permalink / raw)
To: Ramkumar Ramachandra; +Cc: Junio C Hamano, Git List
On Thu, Mar 21, 2013 at 06:02:32PM +0530, Ramkumar Ramachandra wrote:
> > git log --format=%H --name-status --diff-filter=A -- path1 path2 |
> > grep ^A |
> > tail -1
>
> Great! I just learnt about --name-status now.
You can also use "--name-only", but the parsing is a little less robust.
> Nit: tail -<n> is deprecated in favor of tail -n <n>, I think. It's
> nicer to have definite fixed command line options, as opposed to
> parsing an arbitrary -(*) and deciding if \1 is a \d+.
Yeah, POSIX has always specified "-n" for tail, as well as for head. I
remember in the late 90's and early 00's running into systems where
POSIX "head -n" did not work, and you _had_ to use "head -1". I don't
recall now if that was the case for tail, too, nor what system that was
on (but if I had to guess, I'd say pre-Solaris SunOS).
So yeah. Using "tail -n 1" is probably a better idea in the long run.
-Peff
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-03-21 13:26 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-20 20:21 Which file is older in history? Ramkumar Ramachandra
2013-03-20 20:46 ` Junio C Hamano
2013-03-21 11:59 ` Ramkumar Ramachandra
2013-03-21 12:21 ` Jeff King
2013-03-21 12:24 ` Jeff King
2013-03-21 12:32 ` Ramkumar Ramachandra
2013-03-21 13:26 ` Jeff King
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).