user3595632 user3595632 - 1 year ago 109
Git Question

Git: is it possible to use number to add(or diff) file on stage?

What I want to do is,

(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/
modified: spacegraphy/carts/views/
modified: spacegraphy/functional_tests/
modified: spacegraphy/products/static/js/product_detail.js

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

When I want to see difference of
, I want to type like this:

>> git diff 2

is second in the unstaged file list)

Likewise, When I want to add
, I want to type like this:

>> git add 4

Would it be possible? Any idea please?

Answer Source

Yes there actually is. Check out git's interactive staging You will get a menu which is based on numbers.

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

So to diff a file. You would first write 6 to enter diff. Then a list of files will appear that have changes, each with a number. Type the number of the file you want to diff, for example 1. This will output the diff, and you'll get back to the first menu.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download