threads / discuss / 24855

How to query the version of a file?

Subject: How to query the version of a file?

## tl;dr

5 messages between Aug 25, 2010 and Sep 28, 2010.

replies: 4people: 5as markdown or json

Edmond Halley· Aug 25, 2010, 06:33 UTC · lore
Hi,

I have a standalone repository. File a.cpp has 3 versions. For example, I checked out version2(HEAD^).

> git checkout HEAD^ a.cpp

After a few days, I forget which version I have checked out. Is there a git command that can query which version is checked out? "git status" will show there is "changes to be committed", but with no the version information. Thank you!

Best regards, Halley

Todd A. Jacobs· Aug 25, 2010, 13:27 UTC · re: Edmond Halley · lore

Re: How to query the version of a file?

On Wed, Aug 25, 2010 at 2:33 AM, Edmond Halley <halleyinvent@gmail.com> wrote:
Show 6 quoted lines
> I have a standalone repository.
> File a.cpp has 3 versions.
> For example, I checked out version2(HEAD^).
>> git checkout HEAD^ a.cpp
> After a few days, I forget which version I have checked out.
> Is there a git command that can query which version is checked out?

There may be an easier way to do this, but the way I do it is (sort of) documented in http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#Finding-comments-With-given-Content (should be "commits" instead of "comments", but oh well!) and can be tweaked to suit yourself:

    git log --raw --abbrev=40 --pretty=oneline |
    grep -B 24 `git hash-object a.cpp`

There may be other, and possibly more efficient, ways to do this, but it generally works for me.

sandy2010· Sep 28, 2010, 10:49 UTC · re: Edmond Halley · lore

Re: How to query the version of a file?

I do not see the reply to this thread. I'm unable to find how to find the version of a checked out file? Also, how do I view an older version?

-- 
View this message in context: http://git.661346.n2.nabble.com/How-to-query-the-version-of-a-file-tp5459953p5578850.html
Sent from the git mailing list archive at Nabble.com.
Michael J Gruber· Sep 28, 2010, 11:19 UTC · re: sandy2010 · lore

Re: How to query the version of a file?

sandy2010 venit, vidit, dixit 28.09.2010 12:49:
> 
> I do not see the reply to this thread. I'm unable to find how to find the
> version of a checked out file? Also, how do I view an older version?

Todd already answered to your address as well as to the list (3 days ago). Your 2nd question is answered in the same place he pointed you to:

http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#viewing-old-file-versions

Now, what do you think is the top hit when googling "git view older version" ;)

Michael
Pascal Obry· Sep 28, 2010, 11:26 UTC · re: sandy2010 · lore

Re: How to query the version of a file?

On Tue, Sep 28, 2010 at 12:49 PM, sandy2010 <sandeeptt@yahoo.com> wrote:
> I do not see the reply to this thread. I'm unable to find how to find the
> version of a checked out file? Also, how do I view an older version?
No response probably because there is no notion of version of a file in Git.
Each commit is uniquely identified (SHA-1). A file is part of a commit.

I would recommend to read some Git tutorials, books that can be found on the Web. See Git wiki, or the online Pro Git book:

   http://progit.org/book/
Pascal.
-- 
--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595

← back to recent threads