首页 > git commit -m 与 git commit -am 的区别

git commit -m 与 git commit -am 的区别

麻烦解答下 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 addgit 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
【热门文章】
【热门文章】