threads / discuss / 17015

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

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

## tl;dr

4 messages between Jan 6, 2009 and Jan 7, 2009.

replies: 3people: 3as markdown or json

chris@seberino.org· Jan 6, 2009, 05:18 UTC · lore

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· Jan 6, 2009, 06:17 UTC · re: chris@seberino.org · lore

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

On Tue, Jan 6, 2009 at 1:18 PM,  <chris@seberino.org> wrote:
Show 10 quoted lines
> 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· Jan 6, 2009, 06:26 UTC · re: chris@seberino.org · lore

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

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· Jan 7, 2009, 06:55 UTC · re: Junio C Hamano · lore

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

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

← back to recent threads