tags:

views:

52

answers:

1

Let's say I have a file named a.txt. I add it to the staging area, and then I modify it. How could I return it to the way it was when I added it?

+5  A: 

git checkout a.txt

Git tells you this if you type git status:

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# modified:   a
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified:   a
#
abyx
This will check out the copy from HEAD, and not the staging area, unless I'm mistaken. I'd have to RTFM to be sure, but I don't think this is correct.
Daenyth
@Daenyth I've checked it before posting, and you can see the output shows different ways of resetting the files in different states (staged vs. unstaged)
abyx
Ah, I'm incorrect then. Thanks for clarifying that :)
Daenyth
@Daenyth -- you're thinking of 'git checkout branch-name path' or 'git checkout HEAD path'
William Pursell
@William: Thanks! Makes much more sense now.
Daenyth