我有一个经过大量修改的源代码树。我选择了一大堆文件,然后将其放入文件中。有没有办法只提交这些?
我想要类似的东西:
git commit --files "/tmp/files-to-commit.txt" -m "Fixed bug"
git add `cat /tmp/files-to-commit.txt`
git commit -m "Fixed bug"
``做shell扩展。因此,如果您在文件中有文件名,则将它们列出来会将它们列为args。
文件已经被标记,因此我不需要使用git add添加它们。此外,我不想删除其他标记在一起的文件,我只想提交一组特定的文件。
我是通过这种方式得到的:
git commit <first-file-of-list> -m "Fixed bug"
然后,从文件列表中删除列表的第一个文件,并使用以下命令提交其他文件:
cat /tmp/files-to-commit.txt|while read file; do
git commit $file --amend --m "Fixed bug"
done
六年后的Git 2.25(Q1 2020),一些命令(git add
,git-commit
,git reset
)学会了从标准输入或命名文件中获取路径规范,而不是将其用作命令行参数。
请参阅commit e440fc5的commit 66a25a7,commit 64bac8d,commit d137b50,commit 24e4750,commit add9770(2019年11月19日和Alexandr Miloslavskiy (SyntevoAlex
)(2019年11月6日))。[[在SyntevoAlex
中由Junio C Hamano -- gitster
--合并,2019年12月10日
示例:
[
gitster
:支持commit c58ae96选项签名人:Alexandr Miloslavskiy
为简单起见而做出的决定:
目前,即使
commit
不是commit
,也宣布--pathspec-from-file
与--pathspec-from-file
不兼容。这样的用例不是真的期望的。另外,它需要更改为--interactive/--patch
。不允许同时在args和文件中传递pathspec
<file>
现在包括:
stdin
Pathspec在
所述。interactive_add()
中传递,而不是在命令行参数中传递。如果git commit
man page正好是git commit
,则使用标准输入。Pathspec元素由LF或CR / LF分隔。可以引用Pathspec元素,如配置变量--pathspec-from-file=<file>:
<file>
仅对
<file>
有意义。Pathspec元素用-
字符分隔,所有其他字符按字面意义使用(包括换行和引号)。