最常见的 Git 命令序列是:
git add .
git commit -m "Message"
我已经搜索了一个本地 Git 命令来用一行完成它,但令人惊讶的是找不到它。至少有两个大线程关注这个问题HERE和 HERE ,但令人惊讶的是,他们有高票的答案没有完成这项工作或使用其他黑客来完成。
上面链接的第一个线程中投票最高的解决方案建议定义一个宏
git config --global alias.add-commit '!git add -A && git commit'
它的缺点是必须为每个新的软件环境一次又一次地这样做。第二次投票解决方案
git commit -a -m "message"
不起作用 - 它不添加新文件!其他“解决方案”涉及在一行中编写相同的两个命令 - 这在打字方面没有任何优势!
此外,Pro Git - 其中一本著名书籍在第 22 页指出:
2.2.7 Skipping the Staging Area
Although it can be amazingly useful for crafting commits exactly how you want them, the staging area is sometimes a bit more complex than you need in your workflow. If you want to skip the staging area, Git provides a simple shortcut. Providing the -a option to the git commit command makes Git automatically stage every file that is already tracked before doing the commit, letting you skip the git add part...
重点是我的 - 这确实只适用于已经跟踪的文件。但是您的新文件永远不会被跟踪(或者我可以更改设置以使其被跟踪吗?),因此您不能使用该命令添加和提交!
我正在寻找一个干净的单行解决方案由标准 git 软件提供,没有额外的 hack。鉴于 Git 如此丰富的高级选项,很难相信这样的命令不存在。如果这里有什么我遗漏的,我会很乐意学习!
最佳答案
据我所知,没有用于此的 native 命令,并且您已经链接到的问题似乎支持这种观点。可能是因为它有可能导致问题,尽管您自己可能有充分的理由希望以这种方式工作。
但是您可以调整您已经提到的命令之一:
git config --system alias.add-commit '!git add -A && git commit'
将 --global 替换为 --system 将一次性为一台机器上的每个帐户配置别名。您当然需要使用有权写入 /etc 中的系统 gitconfig 文件的帐户运行上述命令
这不是完美的答案,但它可能会让您更接近您想要的,至少从实际的角度来看是这样。
关于Git 在一个 _native git_ 命令中添加并提交所有文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29533464/