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
#