git 多人协作开发的使用(二)---命令使用

本文详细介绍了在使用Git过程中遇到的各种情况,包括如何撤销已修改但未提交的文件更改,以及如何从暂存区撤回已添加的更改等内容。

前面介绍了上传代码的流程,在开发中,很多时候我们可以没有这么顺利,会有很多状况出现,本篇文章就是汇总这些使用:

  • 文件修改,但是未执行git add

文件修改,回退

我们更改了test项目下a文件中的内容,在a文件中添加了一个字符串

  • 未执行git add

    此时我们发现a的更改有误,需要回到文件更改前。

     git checkout a   //回到文件更改前 放弃改变
    
xu:test xiaokai$ vim a //编辑完成后,先按下esc,然后 shift + ":",输入wq保存退出。
xu:test xiaokai$ 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 checkout -- <file>..." to discard changes in working directory)

    modified:   a   //red

no changes added to commit (use "git add" and/or "git commit -a")
xu:test xiaokai$ 
  • 执行了git add

        git reset HEAD a
    

    当执行了git add 后,就是已经将更改的内容添加到了暂存区,此时,想将添加的内容从暂存区回退到,未添加时,使用git reset HEAD a.

xu:test xiaokai$ git add a
xu:test xiaokai$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   a   //green

xu:test xiaokai$ git reset HEAD a
Unstaged changes after reset:
M   a
xu:test xiaokai$ 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 checkout -- <file>..." to discard changes in working directory)

    modified:   a  //red

no changes added to commit (use "git add" and/or "git commit -a")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值