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就直接把两步结合起来了

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值