git checkout not discard changes

1. checkout one branch, show status

user@vbox:/mnt/tmp$ git checkout master
Switched to branch 'master'
user@vbox:/mnt/tmp$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   testfile.c
#
no changes added to commit (use "git add" and/or "git commit -a")

2. show diff, turns out no diff
user@vbox:/mnt/tmp$ git diff

user@vbox:/mnt/tmp$

3. checkout modified file, show status, testfile.c doesn't change.

user@vbox:/mnt/tmp$ git checkout -- testfile.c

user@vbox:/mnt/tmp$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   testfile.c
#
no changes added to commit (use "git add" and/or "git commit -a")

4. solution. Don't know why, but this works for me.
user@vbox:/mnt/tmp$ git add testfile.c
user@vbox:/mnt/tmp$ git status
# On branch master
nothing to commit, working directory clean
user@vbox:/mnt/tmp$

上一篇:sobel算子原理及opencv源码实现


下一篇:负载均衡-基础-一致性哈希算法及java实现