1 只修改一个文件,查看当前状态
shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add ..." to update what will be committed)
# (use "git checkout -- ..." 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")
$ 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 ..." to update what will be committed)
# (use "git checkout -- ..." 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 把文件从当前的修改状态会退到上次修改状态,有没有两个减号 --效果一样,可能其他作用有待发现
shuohailhl@SHUOHAILHL-PC /f/ggg/jingwei/jingwei-webconsole (master)
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# modified: src/main/filter/dev-filter.properties
#
# Changes not staged for commit:
# (use "git add ..." to update what will be committed)
# (use "git checkout -- ..." to discard changes in working directory)
#
# modified: src/main/filter/dev-filter.properties
#
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 ..." to update what will be committed)
# (use "git checkout -- ..." 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")
(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 ..." to unstage)
#
# modified: src/main/filter/dev-filter.properties
#
# Changes not staged for commit:
# (use "git add ..." to update what will be committed)
# (use "git checkout -- ..." 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 ..." to unstage)
#
# modified: src/main/filter/dev-filter.properties
#
# Changes not staged for commit:
# (use "git add ..." to update what will be committed)
# (use "git checkout -- ..." 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 ..." to unstage)
#
# modified: src/main/filter/dev-filter.properties
#
(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 ..." to unstage)
#
# modified: src/main/filter/dev-filter.properties
#
# Changes not staged for commit:
# (use "git add ..." to update what will be committed)
# (use "git checkout -- ..." 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 ..." to unstage)
#
# modified: src/main/filter/dev-filter.properties
#