# Contents of file for a commit

6 messages from 2008-01-27 to 2008-01-27. Participants: Bill Lear, Jeff King, Shawn O. Pearce.
Thread: https://gitlist.dev/t/11757

## Bill Lear, 2008-01-27 04:22

Subject: Contents of file for a commit
Message-ID: <18332.1826.220373.129812@lisa.zopyra.com>
URL: https://gitlist.dev/e/18332.1826.220373.129812%40lisa.zopyra.com

```
How can I do the equivalent of 'cvs co -r <commit> -p <file>' in git?
I want to see the entire contents of a file as it existed after a
particular commit was introduced.


Bill

```

## Jeff King, 2008-01-27 04:28

Subject: Re: Contents of file for a commit
Message-ID: <20080127042854.GA25133@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20080127042854.GA25133%40coredump.intra.peff.net
In-Reply-To: <18332.1826.220373.129812@lisa.zopyra.com>

```
On Sat, Jan 26, 2008 at 10:22:58PM -0600, Bill Lear wrote:

> How can I do the equivalent of 'cvs co -r <commit> -p <file>' in git?
> I want to see the entire contents of a file as it existed after a
> particular commit was introduced.

Try 'git show <commit>:<file>'.

-Peff

```

## Shawn O. Pearce, 2008-01-27 04:40

Subject: Re: Contents of file for a commit
Message-ID: <20080127044027.GS24004@spearce.org>
URL: https://gitlist.dev/e/20080127044027.GS24004%40spearce.org
In-Reply-To: <18332.1826.220373.129812@lisa.zopyra.com>

```
Bill Lear <rael@zopyra.com> wrote:
> How can I do the equivalent of 'cvs co -r <commit> -p <file>' in git?
> I want to see the entire contents of a file as it existed after a
> particular commit was introduced.

`git checkout $commit -- $path`

would get the file at that version into your working directory,
but also will update the index, thus staging the file for the
next commit.

You can also just view the file if you don't want those changes
to be made:

`git show $commit -- $path`

If you are scripting, use cat-file directly to avoid any CRLF
conversion or whatnot:

`git cat-file blob $commit:$path`

-- 
Shawn.

```

## Jeff King, 2008-01-27 04:49

Subject: Re: Contents of file for a commit
Message-ID: <20080127044944.GA25247@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20080127044944.GA25247%40coredump.intra.peff.net
In-Reply-To: <20080127044027.GS24004@spearce.org>

```
On Sat, Jan 26, 2008 at 11:40:27PM -0500, Shawn O. Pearce wrote:

> You can also just view the file if you don't want those changes
> to be made:
> 
> `git show $commit -- $path`

That doesn't work. It says "show me $commit, but limited by $path". So
if $path was changed, you see the commit log and diff. If it wasn't, you
see nothing.

-Peff

```

## Shawn O. Pearce, 2008-01-27 05:01

Subject: Re: Contents of file for a commit
Message-ID: <20080127050127.GT24004@spearce.org>
URL: https://gitlist.dev/e/20080127050127.GT24004%40spearce.org
In-Reply-To: <20080127044944.GA25247@coredump.intra.peff.net>

```
Jeff King <peff@peff.net> wrote:
> On Sat, Jan 26, 2008 at 11:40:27PM -0500, Shawn O. Pearce wrote:
> 
> > You can also just view the file if you don't want those changes
> > to be made:
> > 
> > `git show $commit -- $path`
> 
> That doesn't work. It says "show me $commit, but limited by $path". So
> if $path was changed, you see the commit log and diff. If it wasn't, you
> see nothing.

Gah.  Indeed.  I should have suggested to Bill:

`git show $commit:$path`

sorry about the confusion, and thanks for the clarification.  :-)

-- 
Shawn.

```

## Bill Lear, 2008-01-27 14:31

Subject: Re: Contents of file for a commit
Message-ID: <18332.38352.952940.201025@lisa.zopyra.com>
URL: https://gitlist.dev/e/18332.38352.952940.201025%40lisa.zopyra.com
In-Reply-To: <20080127050127.GT24004@spearce.org>

```
On Sunday, January 27, 2008 at 00:01:28 (-0500) Shawn O. Pearce writes:
>Jeff King <peff@peff.net> wrote:
>> On Sat, Jan 26, 2008 at 11:40:27PM -0500, Shawn O. Pearce wrote:
>> 
>> > You can also just view the file if you don't want those changes
>> > to be made:
>> > 
>> > `git show $commit -- $path`
>> 
>> That doesn't work. It says "show me $commit, but limited by $path". So
>> if $path was changed, you see the commit log and diff. If it wasn't, you
>> see nothing.
>
>Gah.  Indeed.  I should have suggested to Bill:
>
>`git show $commit:$path`
>
>sorry about the confusion, and thanks for the clarification.  :-)

Ok, looks like that works.  Thanks all.


Bill

```
