[英]Is there a command/shortcut to add only certain files to INDEX when staging files in git (using terminal)?
例如,如果我有8個不同的文件需要提交,但是我想一起提交其中的4個,那么如何在不鍵入完整路徑或復制/粘貼的情況下僅添加這4個文件呢?
編輯:更具體地說,我正在尋找一種從編號列表中進行選擇的方法:
偽造的例子:
Git status
File.txt
File.txt
File.txt
File.txt
File.txt
File.txt
Git add 1,3,6
這取決於文件的名稱。 如果有一種模式可以用來區別要添加的文件,則可以使用glob通過git add
指定子集。
一個例子:
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
file1.txt
file2.txt
file3.txt
file4.txt
file5.txt
file6.txt
file7.txt
file8.txt
nothing added to commit but untracked files present (use "git add" to track)
$ git add file[1-4].txt
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: file1.txt
new file: file2.txt
new file: file3.txt
new file: file4.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
file5.txt
file6.txt
file7.txt
file8.txt
或者,您可以使用git add --interactive
:
$ git add --interactive
*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
What now> 4
1: file1.txt
2: file2.txt
3: file3.txt
4: file4.txt
5: file5.txt
6: file6.txt
7: file7.txt
8: file8.txt
Add untracked>> 1-4
* 1: file1.txt
* 2: file2.txt
* 3: file3.txt
* 4: file4.txt
5: file5.txt
6: file6.txt
7: file7.txt
8: file8.txt
Add untracked>>
added 4 paths
*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
What now> 7
Bye.
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: file1.txt
new file: file2.txt
new file: file3.txt
new file: file4.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
file5.txt
file6.txt
file7.txt
file8.txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.