This answer says that git commit --include
is equivalent to a git add
of the specified files, followed by a git commit
.
The man
-page says:
Before making a commit out of staged contents so far, stage the contents of paths given on the command line as well.
However, I can't get it to work as advertised:
% git init
Initialized empty Git repository in /tmp/git/.git/
% touch foo
% git commit -m "Why doesn't this work?" --include foo
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
foo
nothing added to commit but untracked files present (use "git add" to track)
How do I get it to work as it's apparently supposed to?
Historical note: This question previously used the functionally equivalent command git commit -m "Why doesn't this work?" --include -- foo
, which confused some people by the inclusion of the unnecessary --
pathspec separator.