# How make "git checkout <commit> <file>" *not* alter index?

4 messages from 2009-01-06 to 2009-01-07. Participants: chris@seberino.org, Jike Song, Junio C Hamano.
Thread: https://gitlist.dev/t/17015

## chris@seberino.org, 2009-01-06 05:18

Subject: How make "git checkout <commit> <file>" *not* alter index?
Message-ID: <20090106051852.GA3278@seberino.org>
URL: https://gitlist.dev/e/20090106051852.GA3278%40seberino.org

```
I want to pull an old version of a file into my local directory and make it
appear like work I haven't added to index yet...


So how modify


git checkout <commit> <file>

to do this?

cs

```

## Jike Song, 2009-01-06 06:17

Subject: Re: How make "git checkout <commit> <file>" *not* alter index?
Message-ID: <df9815e70901052217m3bdb29e4y8f28a1300169c1ea@mail.gmail.com>
URL: https://gitlist.dev/e/df9815e70901052217m3bdb29e4y8f28a1300169c1ea%40mail.gmail.com
In-Reply-To: <20090106051852.GA3278@seberino.org>

```
On Tue, Jan 6, 2009 at 1:18 PM,  <chris@seberino.org> wrote:
> I want to pull an old version of a file into my local directory and make it
> appear like work I haven't added to index yet...
>
>
> So how modify
>
>
> git checkout <commit> <file>
>
> to do this?

I have a stupid way to do this:

 $ git show v2.6.12:Makefile > Makefile
 $ git diff --cached  /* no outputs */

Ugly but seems work.

-- 
Thanks,
Jike

```

## Junio C Hamano, 2009-01-06 06:26

Subject: Re: How make "git checkout <commit> <file>" *not* alter index?
Message-ID: <7vk599ne6a.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vk599ne6a.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <20090106051852.GA3278@seberino.org>

```
chris@seberino.org writes:

> I want to pull an old version of a file into my local directory and make it
> appear like work I haven't added to index yet...

The command to reset the index can be used any time you have unwanted
changes to it and pretend you started from the latest commit (aka HEAD).

Typically, you use it to recover from a "git add" you did by mistake,
e.g.

    $ edit frotz.c nitfol.c
    $ git add frotz.c nitfol.c
    ... oops, I do not want the changed frotz.c in the next commit.
    $ git reset frotz.c
    $ git commit -m 'update nitfol.c for such and such reasons'

This procedure can be used after you have smudged the index in an unwated
way, and is not limited to "git add" (or "git add -p").  In this case, you
can do:

    $ git checkout HEAD~43 Makefile
    $ git reset Makefile

```

## chris@seberino.org, 2009-01-07 06:55

Subject: Re: How make "git checkout <commit> <file>" *not* alter index?
Message-ID: <20090107065538.GA10617@seberino.org>
URL: https://gitlist.dev/e/20090107065538.GA10617%40seberino.org
In-Reply-To: <7vk599ne6a.fsf@gitster.siamese.dyndns.org>

```
On Mon, Jan 05, 2009 at 10:26:05PM -0800, Junio C Hamano wrote:
>     $ git checkout HEAD~43 Makefile
>     $ git reset Makefile

Thank you very much.  git reset looks that just what I need.

cs

```
