麻烦解答下 git commit -m 与 git commit -am 的区别
当修改已经通过git add <change file>
将其添加到stage
,可以通过git commit -m "<message>"
为这所有已经进入stage
的改变添加一个commit
信息。什么是在stage
中?看下面
如果你的文件之前已经提交过,但这次的改动还没有进stage
,如下:
可以直接使用git commit -am "<message>"
,将所有修改,但未进stage
的改动加入stage
,并记录commit
信息。(某种程度上相当于git add
和git commit -m
的组合技,前提是被改动文件已经是tracked
)
git commit -am "str"
#等同于
git commit -a -m "str"
我们运行下
man git commit
来获取a
参数的意义即知区别了。
OPTIONS
-a, --all
Tell the command to automatically stage files that have been modified and >deleted, but new files you have not told Git about are not affected.
意思是说
自动把当前所有修改和删除文件放到栈上,但你没有添加过的不会受影响。
拓展
通常我们提交git的时候都是
git add .
git commit -m "some str"
git push
这三大步,而实际上,你只需要两条命令就够了,除非有新的文件要被添加进去。
git commit -am "some str"
git push