【Git】add命令对文件组合提交


【命令】:
  $ git add -i
【使用场景】:
  修改一堆文件后,希望这些改动能放到若干提交而不是混杂在一起成为一个提交
【怎样使用】:
  【1】怎样加入文件到暂存区?
  【2】怎样撤销暂存区的文件?
  【3】怎样查看暂存区文件改动内容;
  【4】怎样暂存文件的部分内容;

【详细操作如下】:

【1】 加入文件到暂存区步骤

#1.进入交互模式
      $ git add -i
            staged     unstaged path
      1:    unchanged        +0/-1 TODO
      2:    unchanged        +1/-1 index.html
      3:    unchanged        +5/-1 lib/simplegit.rb
      *** Commands ***
      1: status     2: update      3: revert     4: add untracked
      5: patch      6: diff        7: quit       8: help
#2.选择模式:暂存文件
      What now> 2
                 staged     unstaged path
      1:    unchanged        +0/-1 TODO
      2:    unchanged        +1/-1 index.html
      3:    unchanged        +5/-1 lib/simplegit.rb
#3.选择TODO和index.html文件暂存,*表示被选中
      Update>> 1,2
               staged     unstaged path
      * 1:    unchanged        +0/-1 TODO
      * 2:    unchanged        +1/-1 index.html
        3:    unchanged        +5/-1 lib/simplegit.rb
#4.回车结束
      Update>>[enter]
      updated 2 paths
      *** Commands ***
      1: status     2: update      3: revert     4: add untracked
      5: patch      6: diff        7: quit       8: help
#5.查看完成后文件状态
      What now> 1
               staged     unstaged path
      1:        +0/-1      nothing TODO
      2:        +1/-1      nothing index.html
      3:    unchanged        +5/-1 lib/simplegit.rb

【2】撤销暂存区的文件

#1.进入交互模式
      $ git add -i
               staged     unstaged path
      1:    unchanged        +0/-1 TODO
      2:    unchanged        +1/-1 index.html
      3:    unchanged        +5/-1 lib/simplegit.rb
      *** Commands ***
      1: status     2: update      3: revert     4: add untracked
      5: patch      6: diff        7: quit       8: help
#2.选择模式:revert(撤销模式)
      What now> 3
             staged     unstaged path
      1:        +0/-1      nothing TODO
      2:        +1/-1      nothing index.html
      3:    unchanged        +5/-1 lib/simplegit.rb
#3.选中TODO文件撤销
      Revert>> 1
                 staged     unstaged path
      * 1:        +0/-1      nothing TODO
      2:        +1/-1      nothing index.html
      3:    unchanged        +5/-1 lib/simplegit.rb
#4.回车结束
      Revert>> [enter]
      reverted one path
#5.查看文件状态
      What now> 1
               staged        unstaged path
      1:    unchanged        +0/-1 TODO
      2:        +1/-1        nothing index.html
      3:    unchanged        +5/-1 lib/simplegit.rb

【3】查看暂存区文件改动内容

#1.进入交互模式
      $ git add -i
               staged     unstaged path
      1:    unchanged        +0/-1 TODO
      2:    unchanged        +1/-1 index.html
      3:    unchanged        +5/-1 lib/simplegit.rb
      *** Commands ***
      1: status     2: update      3: revert     4: add untracked
      5: patch      6: diff        7: quit       8: help
#2.显示暂存文件的一个列表,可以从中选择想要查看的暂存区别,跟命令行指定 git diff --cached非常相似
      What now> 6
               staged     unstaged path
      1:        +1/-1      nothing index.html
#3.选择要查看的文件
      Review diff>> 1
      diff --git a/index.html b/index.html
      index 4d07108..4335f49 100644
      --- a/index.html
      +++ b/index.html
      @@ -16,7 +16,7 @@ Date Finder
       

...

- +

你可能感兴趣的:(【Git】add命令对文件组合提交)