git图形化工具GitKraken的使用——撤销工作区的修改(checkout)

首先我初始化一个仓库,并且提交了一个文件:
这里写图片描述

情景一

在工作区对index.html做了一些修改,还没有add到暂存区,并且暂存区没有index.html的修改。

我们先来执行 git status 来查看下状态:

$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)
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:   index.html

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

这里git告诉你可以使用命令git checkout -- <file>... 可以丢弃工作区的修改(目前还在工作区),对应的GitKraken上的操作为:
这里写图片描述

执行操作之后你会发现,之前工作区的修改已经没了,现在index.html回到了和版本库一样的状态。

情景二

对index.html做了一次更改,然后add到暂存区,接着又对它做了更改

这里写图片描述

$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   index.html

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:   index.html

此时我们执行:git checkout --index.html 就会撤销工作区的更改,回到和暂存区一样的状态:

$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   index.html
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值