Git提交过程分为两个部分。首先,您需要“暂存”单个文件,然后执行“提交”命令,将“暂存”的文件添加到代码库中。因此,如果您想要“暂存”文件,首先需要使用“git add”命令:
git add myfile1
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: file2.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# file3.txt
如果我想提交file2.txt和file3.txt的更改,可以执行以下操作:
git add file2.txt
git add file3.txt
git commit
这将提交新文件和对file2.txt所做的更改。
然而,如果我只使用 git commit -a 命令,则只会提交 file2.txt 的更改,而新文件(file3.txt)将被忽略。
因此,为了达到相同的效果,我也可以执行以下操作:
git add file3.txt
git commit -a