threads / discuss / 17609

Question about removing changes from the index

Subject: Question about removing changes from the index

## tl;dr

5 messages between Feb 6, 2009 and Feb 6, 2009.

replies: 4people: 4as markdown or json

Gustav Hållberg· Feb 6, 2009, 13:57 UTC · lore

I'm wondering if there's anyone who can recommend a smart way to "reset" the index entry for individual files to the contents of HEAD, in effect, removing any previous change between HEAD and the index (for those files).

I'm aware that 'git gui' lets you do this (in a human-friendly way) but I want to do this from a script (and am not concerned about the human-friendliness, as long as it's not too programmer-unfriendly).

Thanks, Gustav

Björn Steinbrink· Feb 6, 2009, 14:09 UTC · re: Gustav Hållberg · lore

Re: Question about removing changes from the index

On 2009.02.06 14:57:35 +0100, Gustav Hållberg wrote:
> I'm wondering if there's anyone who can recommend a smart way to
> "reset" the index entry for individual files to the contents of HEAD,
> in effect, removing any previous change between HEAD and the index
> (for those files).
Believe it or not, it's "git reset" ;-)
git reset -- file

You can only reset the index entry for that file to some older version, e.g. "git reset HEAD~5 -- file".

Björn
Matthieu Moy· Feb 6, 2009, 14:11 UTC · re: Gustav Hållberg · lore

Re: Question about removing changes from the index

Gustav Hållberg <gustav@gmail.com> writes:
> I'm wondering if there's anyone who can recommend a smart way to
> "reset" the index entry for individual files to the contents of HEAD,
> in effect, removing any previous change between HEAD and the index
> (for those files).

Isn't "git reset -- path" what you want? Or perhaps "git checkout HEAD -- path" if you also want to reset the file content.

-- 
Matthieu
Sitaram Chamarty· Feb 6, 2009, 14:14 UTC · re: Gustav Hållberg · lore

Re: Question about removing changes from the index

On 2009-02-06, Gustav Hållberg <gustav@gmail.com> wrote:
> I'm wondering if there's anyone who can recommend a smart way to
> "reset" the index entry for individual files to the contents of HEAD,
> in effect, removing any previous change between HEAD and the index
> (for those files).

err.. 'git reset HEAD -- file'? The man page says "The second form with paths is used to revert selected paths in the index from a given commit, without moving HEAD."

← back to recent threads