# Restoring files from old commits

8 messages from 2007-07-14 to 2007-08-15. Participants: Nikodemus Siivola, martin f krafft, Alex Riesen, Junio C Hamano, Salikh Zakirov, Uwe Kleine-König.
Thread: https://gitlist.dev/t/9033

## Nikodemus Siivola, 2007-07-14 12:09

Subject: Restoring files from old commits
Message-ID: <4698BD17.5080205@random-state.net>
URL: https://gitlist.dev/e/4698BD17.5080205%40random-state.net

```
What is the recommended way to restore individual files
(or directories) in the working tree to the content they
had in a given commit?

That is to say, now that Cogito is deprecated, what should
I use instead of cg-restore?

Cheers,

  -- Nikodemus

```

## martin f krafft, 2007-07-14 12:37

Subject: Re: Restoring files from old commits
Message-ID: <20070714123754.GA29622@piper.oerlikon.madduck.net>
URL: https://gitlist.dev/e/20070714123754.GA29622%40piper.oerlikon.madduck.net
In-Reply-To: <4698BD17.5080205@random-state.net>

```
also sprach Nikodemus Siivola <nikodemus@random-state.net> [2007.07.14.1409 +0200]:
> What is the recommended way to restore individual files
> (or directories) in the working tree to the content they
> had in a given commit?

As per my comment on IRC, I think

  git checkout <tree-ish> <path>

is the way.

-- 
martin;              (greetings from the heart of the sun.)
  \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck
 
spamtraps: madduck.bogus@madduck.net
 
"the difference between genius and stupidity
 is that genius has it's limits."
                                                    -- albert einstein

```

## Alex Riesen, 2007-07-14 14:32

Subject: Re: Restoring files from old commits
Message-ID: <20070714143233.GC2544@steel.home>
URL: https://gitlist.dev/e/20070714143233.GC2544%40steel.home
In-Reply-To: <20070714123754.GA29622@piper.oerlikon.madduck.net>

```
martin f krafft, Sat, Jul 14, 2007 14:37:54 +0200:
> also sprach Nikodemus Siivola <nikodemus@random-state.net> [2007.07.14.1409 +0200]:
> > What is the recommended way to restore individual files
> > (or directories) in the working tree to the content they
> > had in a given commit?
> 
> As per my comment on IRC, I think
> 
>   git checkout <tree-ish> <path>
> 
> is the way.

It does not work for directories, though. On can use

    $ git ls-tree -r -z <tree-ish> -- <path> | git update-index -z --index-info
    $ git ls-tree -r --name-only -z <tree-ish> -- <path> | git checkout-index -f -z --stdin

for a more generic way to do this.

P.S. Martin, would you please stop removing people from address lists
and stop using that Mail-Followup-To? People miss their mails when
they are not addressed to them anymore and you doing exactly that.

```

## Junio C Hamano, 2007-07-14 18:50

Subject: Re: Restoring files from old commits
Message-ID: <7vbqeeizue.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vbqeeizue.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20070714143233.GC2544@steel.home>

```
Alex Riesen <raa.lkml@gmail.com> writes:

> martin f krafft, Sat, Jul 14, 2007 14:37:54 +0200:
>> also sprach Nikodemus Siivola <nikodemus@random-state.net> [2007.07.14.1409 +0200]:
>> > What is the recommended way to restore individual files
>> > (or directories) in the working tree to the content they
>> > had in a given commit?
>> 
>> As per my comment on IRC, I think
>> 
>>   git checkout <tree-ish> <path>
>> 
>> is the way.
>
> It does not work for directories, though.

Are you sure about that?  I just did this in my git.git workspace:

	$ mv Documentation Documentation-
        $ git checkout HEAD Documentation/
        $ diff -r Documentation- Documentation

```

## Alex Riesen, 2007-07-15 08:41

Subject: Re: Restoring files from old commits
Message-ID: <20070715084141.GA2568@steel.home>
URL: https://gitlist.dev/e/20070715084141.GA2568%40steel.home
In-Reply-To: <7vbqeeizue.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano, Sat, Jul 14, 2007 20:50:49 +0200:
> Alex Riesen <raa.lkml@gmail.com> writes:
> >
> > It does not work for directories, though.
> 
> Are you sure about that?  I just did this in my git.git workspace:
> 
> 	$ mv Documentation Documentation-
>         $ git checkout HEAD Documentation/
>         $ diff -r Documentation- Documentation
> 

Missed it. Happy now :)

```

## Nikodemus Siivola, 2007-08-15 17:22

Subject: Re: Restoring files from old commits
Message-ID: <6bcc356f0708151022v6cb8c348nb19690c81e489c5d@mail.gmail.com>
URL: https://gitlist.dev/e/6bcc356f0708151022v6cb8c348nb19690c81e489c5d%40mail.gmail.com
In-Reply-To: <20070715084141.GA2568@steel.home>

```
Tangentially related to my previous question:

Every once and a while I want to examine an older version
of a file in an editor.

(The typical case is first looking for the source of a change
with git-blame, and then wanting to look at the original code
and the diff side by side.)

My current (suboptimal, I hope!) way of doing getting the file
is git-cat-file: first look at the commit, then look at the tree,
... till I find the SHA1 for the file I want.

git-checkout <sha1-of-commit> <path>, but that leaves the old
version in both the index and the tree, which feels icky especially
if I'm giving this treatment to multiple files at the same time.

So what I'd like is something like

 git cat-path <commit> <path-in-the-tree-referenced-by-that-commit>

Does this exist, or is this scripting time?

Cheers,

 -- Nikodemus

```

## Salikh Zakirov, 2007-08-15 17:28

Subject: Re: Restoring files from old commits
Message-ID: <f9vd4l$dj6$1@sea.gmane.org>
URL: https://gitlist.dev/e/f9vd4l%24dj6%241%40sea.gmane.org
In-Reply-To: <6bcc356f0708151022v6cb8c348nb19690c81e489c5d@mail.gmail.com>

```
Nikodemus Siivola пишет:
> So what I'd like is something like
> 
>  git cat-path <commit> <path-in-the-tree-referenced-by-that-commit>
> 
> Does this exist, or is this scripting time?

Have you tried

   git show <commit>:<path>

?

```

## Uwe Kleine-König, 2007-08-15 18:27

Subject: Re: Restoring files from old commits
Message-ID: <20070815182709.GC1644@informatik.uni-freiburg.de>
URL: https://gitlist.dev/e/20070815182709.GC1644%40informatik.uni-freiburg.de
In-Reply-To: <6bcc356f0708151022v6cb8c348nb19690c81e489c5d@mail.gmail.com>

```
Hello Nikodemus,

Nikodemus Siivola wrote:
> So what I'd like is something like
> 
>  git cat-path <commit> <path-in-the-tree-referenced-by-that-commit>
Try:

	git show  <commit>:<path-in-the-tree-referenced-by-that-commit>

Best regards
Uwe

-- 
Uwe Kleine-König

http://www.google.com/search?q=half+a+cup+in+teaspoons

```
