git commit -m 与 git commit -am

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19877818/
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-10 17:16:41  来源:igfitidea点击:

git commit -m vs. git commit -am

gitgithub

提问by slindsey3000

Seems easy but I just don't get it. I am in the root of my application.

看起来很简单,但我就是不明白。我在我的应用程序的根目录中。

Here is my workflow.

这是我的工作流程。

git add .
git commit -m "added a new feature some files changed"
git push heroku master

This usually works. All my changes are pushed.

这通常有效。我所有的更改都被推送了。

But sometimes I have a file that I change but when I push to Heroku the changes are not there for THAT ONE FILE... but for most of the files the changes are there...

但有时我有一个我更改的文件,但是当我推送到 Heroku 时,该文件没有更改......但对于大多数文件来说,更改都在那里......

But if I do

但如果我这样做

git add .
git commit -am "added a new feature some files changed"
git push heroku master

Everything (all changes) are pushed to Heroku

一切(所有更改)都被推送到 Heroku

回答by Davin Tryon

From the docs:

文档

git commit -a automatically stage all tracked, modified files before the commitIf you think the git add stage of the workflow is too cumbersome, Git allows you to skip that part with the -a option. This basically tells Git to run git add on any file that is "tracked" - that is, any file that was in your last commit and has been modified. This allows you to do a more Subversion style workflow if you want, simply editing files and then running git commit -a when you want to snapshot everything that has been changed. You still need to run git add to start tracking new files, though, just like Subversion.

git commit -a在提交前自动暂存所有跟踪、修改的文件如果您认为工作流的 git add 阶段过于繁琐,Git 允许您使用 -a 选项跳过该部分。这基本上告诉 Git 对任何被“跟踪”的文件运行 git add - 也就是说,任何在您上次提交并已被修改的文件。如果需要,这允许您执行更多 Subversion 风格的工作流程,只需编辑文件,然后运行 ​​git commit -a 当您想要对已更改的所有内容进行快照时。不过,您仍然需要运行 git add 来开始跟踪新文件,就像 Subversion 一样。

Using the option -amallows you to add and create a message for the commit in one command.

使用该选项-am允许您在一个命令中为提交添加和创建消息。

回答by Juyal Jee

I would suggest, if you only changed one file then you might do something like this:

我建议,如果您只更改了一个文件,那么您可能会执行以下操作:

git add "Your_file.txt"
git commit -m "added a new feature in a file"
git push heroku master

Or if you changed multiple files then you could do something like this:

或者,如果您更改了多个文件,那么您可以执行以下操作:

git add .
git commit -m "some files changed"
git push heroku master

Similarly, you could add and commit all the files on one line with this command:

同样,您可以使用以下命令在一行中添加和提交所有文件:

git commit -am "added a new feature some files changed"
git push heroku master