git add后又修改,如何撤销最后的修改?

比如Readme文件,修改其中内容,运行git status

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")

现在运行git add 将readme.md放到暂存区,然后再看看git status的输出:

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   README.md

现在文件已经暂存,下次提交时就会记录到仓库。假设此时,再修改readme.md,运行git stastus看看:

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   README.md

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

并且运行git status -s,可以得到一种更为紧凑的输出

$ git status -s
MM README.md

输出中标记位有2栏,左边指明了暂存区的状态,右栏指明了工作区的状态。表明readme文件已暂存,暂存后又做了修改。

那么如何撤销第二次的修改?
问题的本质,暂存区的结构
根据上文分析
暂存区中应该有add后的文件快照,暂存区存储的是add后的文件快照和这些快照的索引文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值