2015-10-27 81 views
1

我經常使用git add -p承諾在Git的碎片文件,但不適用於未跟蹤文件的工作:如何在Git中交互添加未跟蹤的文件?

$ git add -p file 
No changes. 

我如何添加這個文件,但不是所有的階段呢?

我想只添加它的一部分,並提交併保留其餘未分離。

回答

4

您可以分兩步執行此操作:

  1. git add -N file

man page:只有

-N, --intent-to-add 記錄的事實,這條道路將在以後添加。路徑條目放置在沒有內容的索引中。除此之外,這是有用的 ,用於顯示這些文件 與git diff的未分配內容並將它們與git commit -a一起提交。

該命令會將文件添加爲空,所以它不會被解除跟蹤,但它們都不會被暫存。

# Initial commit 
# 
# Changes to be committed: 
# (use "git rm --cached <file>..." to unstage) 
# 
# new file: file 
# 
# 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: file 
# 
  • git add -p file
  • 現在該文件被跟蹤和git add -p作品,它應。

    相關問題