I have a source tree with a bunch of modifications. I selected a big list of files and put then into a file. Is there a way to commit only these ones?
I want something like:
git commit --files "/tmp/files-to-commit.txt" -m "Fixed bug"
I have a source tree with a bunch of modifications. I selected a big list of files and put then into a file. Is there a way to commit only these ones?
I want something like:
git commit --files "/tmp/files-to-commit.txt" -m "Fixed bug"
git add `cat /tmp/files-to-commit.txt`
git commit -m "Fixed bug"
The `` do shell expansion. So if you have the names of files in a file, cat'ing them out will list them as args.
The files was stagged already, therefore I did not need to add them using git add. Besides, I didn't want to remove other files stagged together, I just wanted to commit a specific set of files.
I got it by this way:
git commit <first-file-of-list> -m "Fixed bug"
Then, removed the first-file-of-list from file list and commit the others using:
cat /tmp/files-to-commit.txt|while read file; do
git commit $file --amend --m "Fixed bug"
done
With Git 2.25 (Q1 2020), 6 years later, a few commands (git add
, git-commit
, git reset
) learned to take the pathspec from the standard input or a named file, instead of taking it as the command line arguments.
See commit e440fc5, commit 66a25a7, commit 64bac8d, commit d137b50, commit 24e4750 (19 Nov 2019), and commit add9770 (06 Nov 2019) by Alexandr Miloslavskiy (SyntevoAlex
).
(Merged by Junio C Hamano -- gitster
-- in commit c58ae96, 10 Dec 2019)
Example:
commit
: support the--pathspec-from-file
optionSigned-off-by: Alexandr Miloslavskiy
Decisions taken for simplicity:
For now,
--pathspec-from-file
is declared incompatible with--interactive/--patch
, even when<file>
is notstdin
.
Such use case it not really expected.
Also, it would require changes tointeractive_add()
.It is not allowed to pass pathspec in both args and file
The git commit
man page now includes:
--pathspec-from-file=<file>:
Pathspec is passed in
<file>
instead of commandline args.
If<file>
is exactly-
then standard input is used.
Pathspec elements are separated by LF or CR/LF.
Pathspec elements can be quoted as explained for the configuration variablecore.quotePath
--pathspec-file-nul:
Only meaningful with
--pathspec-from-file
.
Pathspec elements are separated withNUL
character and all other characters are taken literally (including newlines and quotes).
Still with Git 2.25 (Q1 2020), the above series (teaching "--pathspec-from-file
" to "git commit
") forgot to make the option incompatible with "--all
", which has been corrected.
See commit 509efef (16 Dec 2019) by Alexandr Miloslavskiy (SyntevoAlex
).
(Merged by Junio C Hamano -- gitster
-- in commit ff0cb70, 25 Dec 2019)
commit
: forbid --pathspec-from-file --allReported-by: Phillip Wood
Signed-off-by: Alexandr MiloslavskiyI forgot this in my previous patch
--pathspec-from-file
forgit commit
(Commit e440fc58).
When both--pathspec-from-file
and--all
were specified,--all
took precedence and--pathspec-from-file
was ignored.
Before--pathspec-from-file
was implemented, this case was prevented by this check inparse_and_validate_options()
:die(_("paths '%s ...' with -a does not make sense"), argv[0]);
It is unfortunate that these two cases are disconnected.
This came as result of how the code was laid out before my patches, wherepathspec
is parsed outside ofparse_and_validate_options()
. This branch is already full of refactoring patches and I did not dare to go for another one.Fix by mirroring
die()
for--pathspec-from-file
as well.