【问题标题】:Git - Automatically track all files in a directory [duplicate]Git - 自动跟踪目录中的所有文件[重复]
【发布时间】:2012-05-25 17:31:03
【问题描述】:

可能重复:
git add -A, git commit in one command?

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

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

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

【问题讨论】:

标签: git


【解决方案1】:

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 使用一个两阶段的过程来获取从 working directoryrepository 的更改。像git commit -a 这样的包罗万象的方法 会起作用,但它会导致混乱的非原子提交。我会提倡更小、更集中的提交,而不是使用你正在寻找的包罗万象的方法。

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

git-status 是你的朋友 :)

注意:git-add 确实将文件添加到 存储库git commit 提交来自staging arearepository 的东西,不是 来自working area。起初这可能看起来很奇怪,但提供了更大的灵活性。请参阅another answer 了解更多信息。

【讨论】:

    【解决方案2】:

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

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

    命令是g freeze -m "commit msg"

    它适用于添加、删除和更改。您正在冻结一个状态..从第一天开始就应该这样做。

    【讨论】:

    • 或者您可以跳过 G2 并为其添加别名:git config alias.freeze "!git add -A &amp;&amp; git commit"
    • 确实,别名更像这样 freeze="!f() { ( [ -z $@ ] && git add -A || git add -A "$@" ) && git st ; }; F”。 G2 提供更多...
    • G2 提供更多功能......看看冻结是如何实现的github.com/orefalo/g2/blob/master/cmds/g2-freeze.sh
    • 我做到了,这就是我得到别名的地方(它的工作方式相同:git freeze -m "COMMIT ALL THE THINGS")。 G2 看起来很酷很方便,但是对于这个问题来说它是多余的。 OP 想要一个命令来添加和提交工作副本中的所有内容,而 vanilla Git 可以处理得很好。
    • 我只能同意这是矫枉过正的事实。
    猜你喜欢
    • 2015-12-25
    • 2018-07-07
    • 2015-09-02
    • 2017-01-16
    • 2013-09-01
    • 2018-07-21
    • 2016-12-19
    • 2011-03-08
    • 2013-06-13
    相关资源
    最近更新 更多