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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26407059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:28:29  来源:igfitidea点击:

git add and commit single tracked file in one command

gitalias

提问by BrodieG

I'm looking for the equivalent of git commit -am "blah blah"but for just a single file. If I try:

我正在寻找等效于git commit -am "blah blah"但仅用于单个文件的文件。如果我尝试:

git commit my.file -am "blah blah"

I get:

我得到:

fatal: Paths with -a does not make sense.

I looked around but I could only find solutions that suggest using aliases (e.g. this one), but even those don't seem like they could be modified because I need to pass an argument. Do I have to resort to calling git through a shell?

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

It seems like there should be a simpler option for something that I imagine would be extremely common. Right now I'm stuck with:

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

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

回答by John Zwinck

Just omit the -awhich means --allwhich is not what you want. Do this:

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

git commit my.file -m "blah blah"

That will commit only my.file, even if other files are staged (by git add).

my.file即使其他文件被暂存(by git add),那也只会提交。

回答by Sumit Verma

I tried the following command:

我尝试了以下命令:

git commit -m 'your comment' path/to/your/file.txt

I hope, this will help.

我希望这个能帮上忙。