git commit -a 参数设置修改文件后不需要执行 git add 命令,直接来提交,但是文件必须是已经被跟踪的文件
举例
我有两个文件,分别是file1.txt
和readme.txt
,其中file1.txt
没有被跟踪,readme.txt
被跟踪了,而且进行了修改,所以此时我执行git status
显示如下:
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: readme.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
file1.txt
no changes added to commit (use "git add" and/or "git commit -a")
此时我执行git commit -a
命令,应该只会把readme.txt
的修改提交上去
$ git commit -a
[master bdbb064] 测试-a命令
1 file changed, 2 insertions(+), 1 deletion(-)
执行一下git status
看看,发现file1.txt
还是untracked
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
file1.txt
nothing added to commit but untracked files present (use "git add" to track)
总结
如果不带参数-a
,就需要先add一下,把更改给存储起来再commit
直接执行git commit -a
就直接把两步结合起来了