Git:是否可以使用数字在舞台上添加(或差异)文件?

时间:2016-10-03 03:03:59

标签: git

我想做的是,

(spacegraphy) Chois@Chois-MacPro spacegraphy-project $ (feature/carts)git status
On branch feature/carts
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:   spacegraphy/carts/tests/test_views.py
        modified:   spacegraphy/carts/views/cart.py
        modified:   spacegraphy/functional_tests/test_cartitem_at_product_detail.py
        modified:   spacegraphy/products/static/js/product_detail.js

no changes added to commit (use "git add" and/or "git commit -a")

当我想看到spacegraphy/carts/views/cart.py的区别时,我想这样输入:
>> git diff 2
2因为spacegraphy/carts/views/cart.py在非分页文件列表中排名第二)

同样,当我想添加spacegraphy/products/static/js/product_detail.js时,我想输入如下:
>> git add 4

有可能吗?好吗?

1 个答案:

答案 0 :(得分:2)

是的,确实存在。查看git&#39; interactive staging您将获得一个基于数字的菜单。

$ 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
What now>

所以要区分文件。你首先要写6来输入diff。然后会出现一个包含更改的文件列表,每个文件都有一个数字。键入要进行差异的文件的编号,例如1。这将输出差异,然后您将返回第一个菜单。