如何仅提交外部文件中列出的文件名

问题描述 投票:0回答:3

我有一个经过大量修改的源代码树。我选择了一大堆文件,然后将其放入文件中。有没有办法只提交这些?

我想要类似的东西:

git commit --files "/tmp/files-to-commit.txt" -m "Fixed bug"
git version-control
3个回答
1
投票
git add `cat /tmp/files-to-commit.txt`
git commit -m "Fixed bug"

``做shell扩展。因此,如果您在文件中有文件名,则将它们列出来会将它们列为args。


0
投票

文件已经被标记,因此我不需要使用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

0
投票

六年后的Git 2.25(Q1 2020),一些命令(git addgit-commitgit reset)学会了从标准输入或命名文件中获取路径规范,而不是将其用作命令行参数。

请参阅commit e440fc5commit 66a25a7commit 64bac8dcommit d137b50commit 24e4750commit add9770(2019年11月19日和Alexandr Miloslavskiy (SyntevoAlex)(2019年11月6日))。[[在SyntevoAlex中由Junio C Hamano -- gitster --合并,2019年12月10日

示例:

[gitster:支持commit c58ae96选项

签名人:Alexandr Miloslavskiy

为简单起见而做出的决定:

  1. 目前,即使commit不是commit,也宣布--pathspec-from-file--pathspec-from-file不兼容。这样的用例不是真的期望的。另外,它需要更改为--interactive/--patch

  2. 不允许同时在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元素用-字符分隔,所有其他字符按字面意义使用(包括换行和引号)。

© www.soinside.com 2019 - 2024. All rights reserved.