12

可能重复:
git add -A,一个命令中的 git commit?

如果我理解正确,当使用 git 将新文件添加到目录时,我必须调用多个命令以确保文件已提交:

git add <directory name>
git commit -m 'commit comment'

这听起来不对,因为我知道我(和许多其他人)会忘记打电话git add <directory name>,然后最终得到一个缺少所有已创建新文件的项目。似乎我应该能够在一个命令中提交整个目录,包括任何和所有新文件,而无需在上一个命令中指定将所有新文件添加到提交中。我该怎么做呢?

4

2 回答 2

7

git commit -a将提交 git 已知的所有文件:

 -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-status之前使用git-commit来查看暂存的提交文件。

git使用两阶段过程将更改working directoryrepository. 像这样的包罗万象的方法git commit -a 起作用,但它会导致混乱的非原子提交。我会提倡更小、更集中的提交,而不是使用你正在寻找的包罗万象的方法。

这听起来不对,因为我知道我(和许多其他人)会忘记调用 git add...

git-status是你的朋友 :)

注意:git-add不会文件添加到存储库。从thegit commit提交东西,而不是从. 起初这可能看起来很奇怪,但提供了更大的灵活性。有关更多信息,请参阅另一个答案staging arearepositoryworking area

于 2012-05-25T17:40:45.310 回答
2

https://github.com/orefalo/g2获取G2

G2 将通过提供易于使用的宏来帮助您学习 git 命令行。

命令是g freeze -m "commit msg"

它适用于添加、删除和更改。你正在冻结一个状态..这应该是从第一天开始的方式。

于 2012-05-25T17:39:33.097 回答