git commit --include`的语义

问题描述 投票:-1回答:2

This answer表示git commit --include等于指定文件的git add,后跟git commit

但是,我无法正常工作:

% 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)

我应该如何使它正常工作?

git git-commit
2个回答
1
投票

不应该是:

git commit -m "Why doesn't this work?" --include foo

直接在--include之后加上foo(并且没有多余的-)

(假设foo是文件名)


0
投票

git commit只能提交已修改的跟踪文件和暂存的更改。即使使用--include,也无法提交未跟踪的文件。在提交之前,您需要git add未跟踪的文件,并且没有办法解决。

git commit --include可以这样使用:

edit file1 file2 # 2 tracked files
git add file1 # stage new changes
git commit --include file2

git commit --include提交文件1和文件2。如果没有--include,则仅提交file2,而file1将保持暂存状态,等待其他提交或重置。

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