git commit -a的作用

git commit -a 参数设置修改文件后不需要执行 git add 命令,直接来提交,但是文件必须是已经被跟踪的文件

举例

我有两个文件,分别是file1.txtreadme.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就直接把两步结合起来了

猜你喜欢

转载自blog.csdn.net/zjxht62/article/details/115733082