git 回滚单个文件

1  只修改一个文件,查看当前状态

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ 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:   src/main/filter/dev-filter.properties
#
no changes added to commit (use "git add" and/or "git commit -a")

2 使用checkout ,回滚文件

$ git checkout -- src/main/filter/dev-filter.properties
查看结果

$ git status
# On branch master
nothing to commit, working directory clean

使用两个减号 -- 什么意思呢,不用行不行,试试~~

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ 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:   src/main/filter/dev-filter.properties
#
no changes added to commit (use "git add" and/or "git commit -a")

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git checkout  src/main/filter/dev-filter.properties

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git status
# On branch master
nothing to commit, working directory clean
发现git checkout file 把文件从当前的修改状态会退到上次修改状态,有没有两个减号 --效果一样,可能其他作用有待发现

3 文件修改提交到index后,又修改了工作区文件内容

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   src/main/filter/dev-filter.properties
#
# 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:   src/main/filter/dev-filter.properties
#

只从index撤销但不撤销工作区修改,这样工作区可接着上次修改继续,

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git  reset src/main/filter/dev-filter.properties
Unstaged changes after reset:
M       jingwei-webconsole/src/main/filter/dev-filter.properties

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ 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:   src/main/filter/dev-filter.properties
#
no changes added to commit (use "git add" and/or "git commit -a")

第二种情况是不但从index撤销,而且还把work区的修改也撤销 git checkout HEAD,从history既搞index又搞work~~

(1)修改work(2)add 到index(3)修改work   

要把index和work都撤销到上次提交

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   src/main/filter/dev-filter.properties
#
# 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:   src/main/filter/dev-filter.properties
#

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git checkout HEAD src/main/filter/dev-filter.properties

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git status
# On branch master
nothing to commit, working directory clean
第三种情况,把work回退到index中的状态

(1)修改work (2)add到index (3)再修改work  想要回退到index中状态,也就是(2)执行后的状态

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   src/main/filter/dev-filter.properties
#
# 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:   src/main/filter/dev-filter.properties
#

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git checkout src/main/filter/dev-filter.properties

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   src/main/filter/dev-filter.properties
#

第四种情况,想要继续add呢

(1)修改work (2)add到index (3)再修改work,这时候想继续add,就继续add,相当于把最新的更新合并到index中去

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   src/main/filter/dev-filter.properties
#
# 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:   src/main/filter/dev-filter.properties
#

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git add .

shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   src/main/filter/dev-filter.properties
#








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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值