了解何时使用git commit -m和git commit -am [英] Understanding when to use git commit -m and git commit -am
问题描述
我的主要问题是iti是否有意义,只要始终执行 git commit -am
而不是 git add
。其次是 git commit -m
?
我知道,-am表示它将添加所有修改TRACKED文件。因此,在我没有添加任何新文件的情况下,只需运行git commit -am而不是git add就可以了,但是这会被认为是最佳做法:
git add
。
git commit -am消息
无论如何?
甚至相反:
git add -A
git commit -ammessage
:
git add。
git commit -am消息
无论如何?
不,没有这种最佳做法。只要你不想包含任何未跟踪的文件, git add
+ git commit -m
和 git commit -am
将完全相同。
有两种情况需要使用 git add
:
- 如果您想包含未跟踪的文件,并且
- 如果您不想提交所有已更改的内容
第二点尤其是许多人建议不要总是使用 commit -a
:
在编写代码一段时间后,您的工作副本中经常会有几种不同类型的更改(您正在处理的错误修复,无关的重命名,调试的一些临时更改...)。 commit -a
将风险放在一个提交中太多 - 在这些情况下,选择使用 git add
会更好。但是如果你确定你想要提交你改变的所有东西,那么继续使用 git commit -a
。 p>
My main question here is whether iti makes sense to just always do git commit -am
instead of git add
. followed by git commit -m
?
I understand that -am indicates that it will add all changes from modified TRACKED files. So in a situation where I did not add any new files, it would make sense to just run git commit -am instead of git add, but would it be considered best practice to just do:
git add
.
git commit -am "message"
anyway?
or even instead:
git add -A
git commit -am "message"
would it be considered best practice to just do:
git add .
git commit -am "message"
anyway?
No, there is no such "best practice". As long as you do not want to include any untracked files, git add
+ git commit -m
and git commit -am
will do exactly the same.
There are two situations where you need to to use git add
:
- if you want to include untracked files, and
- if you do not want to commit everything that changed
The second point in particular is the reason many people recommend against always using commit -a
:
After working on code for a while, you often have several different types of changes in your working copy (the bugfix you were working on, some unrelated renaming, some temporary changes for debugging...). commit -a
risks putting too much into one commit - in these cases selective use of git add
is better.
But if you are certain you want to commit everything you changed, go ahead and use git commit -a
.
这篇关于了解何时使用git commit -m和git commit -am的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!