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?
views:
52answers:
1
+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
2010-06-15 11:30:48
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
2010-06-15 15:09:53
@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
2010-06-15 15:51:48
Ah, I'm incorrect then. Thanks for clarifying that :)
Daenyth
2010-06-15 16:01:33
@Daenyth -- you're thinking of 'git checkout branch-name path' or 'git checkout HEAD path'
William Pursell
2010-06-16 17:58:39
@William: Thanks! Makes much more sense now.
Daenyth
2010-06-16 18:45:38