开发者

Why are files checked out to previous changesets appearing in the index as modified?

D:\code\gt>git init
Initialized empty Git repository in D:/code/gt/.git/

D:\code\gt>echo Zero > a

D:\code\gt>git add a

D:\code\gt>git commit -m a
[master (root-commit) 392580e] a
 1 files changed, 1 insertions(+), 0 deletions(-)
 c开发者_开发百科reate mode 100644 a

D:\code\gt>echo One > a

D:\code\gt>git add a

D:\code\gt>git commit -m another
[master 271efba] another
 1 files changed, 1 insertions(+), 1 deletions(-)

D:\code\gt>echo Second > a

D:\code\gt>git add a

D:\code\gt>git commit -m "yet another"
[master 8d2041e] yet another
 1 files changed, 1 insertions(+), 1 deletions(-)

D:\code\gt>git status
# On branch master
nothing to commit (working directory clean)

D:\code\gt>git checkout  271ef a

D:\code\gt>git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   a
#

As you can see, I checkout the file in the state it had at the 2nd commit. However, I don't understand why it's already added to the index. Why isn't git letting me do the add?


This is a point which isn't entirely clear from the git checkout documentation, so it's a good question.

When you do:

git checkout COMMIT -- PATH

... the working copy and the index for PATH are updated with the version from COMMIT. So, relative to HEAD, there are indeed changes to that file staged after running that command.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜