git 在一个命令中添加并提交单个跟踪文件

标签 git alias

我正在寻找与 git commit -am "blah blah" 等效的方法,但只是针对单个文件。如果我尝试:

git commit my.file -am "blah blah"

我得到:

fatal: Paths with -a does not make sense.

我环顾四周,但只能找到建议使用别名的解决方案(例如 this one ),但即使是那些似乎也无法修改,因为我需要传递一个参数。我是否必须求助于 calling git through a shell ?

对于我认为非常常见的事情,似乎应该有一个更简单的选择。现在我坚持:

git add my.file
git commit -m "blah blah"

最佳答案

只需省略 -a 这意味着 --all 这不是您想要的。这样做:

git commit my.file -m "blah blah"

这将仅提交 my.file,即使其他文件已暂存(通过 git add)也是如此。

关于git 在一个命令中添加并提交单个跟踪文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26407059/

相关文章:

c# - 如何从 C# 应用程序检索 git Commit Id?

python - 你可以在 Python 中为导入的模块定义别名吗?

dart - 在已发布的 Flutter/Dart 包中重构参数名称时如何保持向后兼容性?

带有可选参数的 git 别名

git - 克隆 Git 存储库后只有主分支可见

使用 git 的 Django 部署,包括与生产相关的文件

git - 注释代码段时如何改进 git diff 输出

shell - 执行shell脚本而不隐式调用sh

方法接收器上的 golang 函数别名

git - 在 PHPStorm 中提交 GIT 之前运行外部工具