tags:

views:

43

answers:

1

I'm wondering if there's a better way to check out the initial version of a file than the obvious way:

git log --reverse [path/to/file]

copy the first sha1

git checkout [found sha1] [path/to/file]

We've got HEAD for the most recent, and the ^ suffix for going back one(or more) but I've not seen any good way to go back to the beginning.

+3  A: 

Well, you ought to use command substitution:

git checkout $(git log --follow --pretty=%H path/to/file | tail -n 1) path/to/file

but there's not going to be anything fundamentally simpler. Git tracks content, not files, so it has no record of "version one of file A" - walking the history's the way to find it.

I took out the --reverse to make the command shorter - it doesn't actually speed things up to use it, because internally, it just finds everything and reverses before printing out, instead of printing as it goes.

If it's something you do a lot (though I have no idea why you would) you could alias it.

Jefromi
i was afraid of that. as to WHY this actually comes up often enough for me to ask about. I use git-p4 at work but it doesn't support p4 branching. so every new p4 branch of a codeline is a new git repo. So, it's not infrequent that i want to compare a file the the first version in the repo to see what has changed in the new branch. it'd be useful to be able to do the similar comparison to a file as it was in a given git branch (not repo) when that branch was created.
masukomi