Git - 自动跟踪目录中的所有文件

Chr*_*row 7 git

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

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

git add <directory name>
git commit -m 'commit comment'
Run Code Online (Sandbox Code Playgroud)

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

sim*_*ont 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.
Run Code Online (Sandbox Code Playgroud)

如果您想确保提交想要的所有内容,可以git-status在a之前使用git-commit,以查看提交的文件.

git采用了两阶段的过程来从变化working directoryrepository.像catch一样的方法git commit -a 起作用,但它会导致混乱的非原子提交.我会提倡较小的,专注的提交,而不是使用像你正在寻找的全能方法.

这听起来不对,因为我知道我(以及许多其他人)会忘记拨打git add ...

git-status 是你的朋友 :)

注意:git-add将文件添加到资料库.git commit从承诺的事情staging arearepository,working area.这一开始可能看起来很奇怪,但提供了更大的灵活性.有关更多信息, 请参阅其他答案


Oli*_*alo 2

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

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

命令是g freeze -m "commit msg".

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