git checkout not discard changes

博客记录了使用Git时的操作过程。先切换到master分支并查看状态,发现testfile.c文件有修改但未暂存;查看差异无结果;尝试检出修改文件,状态仍未改变;最后通过git add testfile.c解决问题,使工作目录变干净。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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$

转载于:https://www.cnblogs.com/hfyinsdu/p/3725591.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值