1

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

我想要类似的东西:

git commit --files "/tmp/files-to-commit.txt" -m "Fixed bug"
4

3 回答 3

1
git add `cat /tmp/files-to-commit.txt`
git commit -m "Fixed bug"

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

于 2013-03-28T17:16:22.990 回答
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
于 2013-04-01T16:51:41.150 回答
0

在 6 年后的 Git 2.25(2020 年第一季度)中,一些命令(git add, git-commit, git reset)学会了从标准输入或命名文件中获取路径规范,而不是将其作为命令行参数。

请参阅Alexandr Miloslavskiy ( ) 的提交 e440fc5提交 66a25a7提交 64bac8d提交 d137b50提交 24e4750(2019 年 11 月 19 日)和提交 add9770(2019 年 11 月 6 日(由Junio C Hamano 合并 -- --提交 c58ae96中,2019 年 12 月 10 日)SyntevoAlex
gitster

例子:

commit: 支持--pathspec-from-file选项

签字人:亚历山大·米洛斯拉夫斯基

为简单起见做出的决定:

  1. 现在,--pathspec-from-file被声明为与 不兼容--interactive/--patch,即使<file>不是stdin
    这样的用例并不是真正预期的。
    此外,它还需要对interactive_add().

  2. 不允许在 args 和 file 中传递 pathspec

git commit手册页现在包括:

--pathspec-from-file=<file>:

传入 Pathspec<file>而不是命令行参数。
如果<file>恰好是,-则使用标准输入。
Pathspec 元素由 LF 或 CR/LF 分隔。
Pathspec 元素可以按照配置变量的说明进行引用core.quotePath

--pathspec-file-nul:

只对 有意义--pathspec-from-file
Pathspec 元素用NUL字符分隔,所有其他字符都按字面意思表示(包括换行符和引号)。


还是Git 2.25(Q1 2020),上面的系列(教“ --pathspec-from-file”到“ git commit”)忘记让选项与“ --all”不兼容,已更正。

请参阅Alexandr Miloslavskiy ( ) 的提交 509efef(2019 年 12 月 16 日(由Junio C Hamano 合并 -- --ff0cb70 提交中,2019 年 12 月 25 日)SyntevoAlex
gitster

commit: 禁止 --pathspec-from-file --all

报告人:Phillip Wood
签字人:Alexandr Miloslavskiy

我在之前的补丁--pathspec-from-file中忘记了这一点git commit(提交e440fc58)。
当同时指定--pathspec-from-fileand时,优先并被忽略。 在实施之前,这种情况是通过这个签入来防止的:--all--all--pathspec-from-file
--pathspec-from-fileparse_and_validate_options()

die(_("paths '%s ...' with -a does not make sense"), argv[0]);

不幸的是,这两个案例是脱节的。
这是因为代码在我的补丁之前是如何布局的,pathspecparse_and_validate_options(). 这个分支已经满是重构补丁了,我不敢再去找了。

也可以通过镜像修复die()--pathspec-from-file

于 2019-12-15T20:52:52.263 回答