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

标签 git

<分区>

Possible Duplicate:
git add -A, git commit in one command?

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

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

这听起来不对,因为我知道我(和许多其他人)会忘记调用 git add <directory name>然后以一个缺少所有创建的新文件的项目结束。看来我应该能够在一个命令中提交整个目录,包括任何和所有新文件,而不必在上一个命令中指定将所有新文件添加到提交中。我该怎么做?

最佳答案

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

git 使用两阶段过程将更改从工作目录 获取到存储库。像 git commit -a 这样的包罗万象的方法 起作用,但它会导致困惑的、非原子的提交。我会提倡较小的、集中的提交,而不是使用您正在寻找的包罗万象的方法。

This doesn't sound right because I know I (and many other people) will forget to call git add...

git-status 是你的 friend :)

注意:git-add 不会将文件添加到存储库git commitstaging area repository 提交东西, working area。乍一看这似乎很奇怪,但提供了更大的灵 active 。参见 another answer想要查询更多的信息。

关于Git - 自动跟踪目录中的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10758904/

相关文章:

git - Visual Studio 未在解决方案资源管理器中显示已提交的文件

git - 多个 ssh key 不起作用

git - 查找特定于分支的第一个提交

git - 如何在 Visual Studio 2010 Beta 2 上安装 GitExtensions?

git - 如何回到之前的master分支

git - Github 页面上的 Powerpoint 演示文稿

django - 混帐/ Django : Granular code permissioning/availability

git - 为Grails构建自动化,代码审查和部署系统

git - 为什么我必须 "git push --set-upstream origin <branch>"?

Git merge 并添加更改 ID