'git add --patch' to include new files?

后端 未结 5 476
不知归路
不知归路 2021-01-29 22:39

When I run git add -p, is there a way for git to select newly made files as hunks to select??

So if I make a new file called foo.java, then run

5条回答
  •  悲&欢浪女
    2021-01-29 23:20

    git add -p is really about adding changes to already tracked files.

    The command to interactively select files to add is git add -i. For example:

    $ git add -i
    
    *** Commands ***
      1: status   2: update   3: revert   4: add untracked
      5: patch    6: diff     7: quit     8: help
    What now> a
      1: another-new.java
      2: new.java
    Add untracked>> 2
      1: another-new.java
    * 2: new.java
    Add untracked>> 
    added one path
    
    *** Commands ***
      1: status   2: update   3: revert   4: add untracked
      5: patch    6: diff     7: quit     8: help
    What now> q
    Bye.
    $ git status
    On branch master
    Changes to be committed:
      (use "git reset HEAD ..." to unstage)
    
            new file:   new.java
    
    Untracked files:
      (use "git add ..." to include in what will be committed)
    
            another-new.java
    

    (The real command has colors which I couldn't cut-and-paste here, so it's nicer than it seems)

    Actually, the patch command of git add -i does the same as git add -p, so the second is a subset of the first (even though I admit I love add -p and hate add -i myself!).

提交回复
热议问题