100

似乎很容易,但我就是不明白。我在我的应用程序的根目录中。

这是我的工作流程。

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

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

但有时我有一个文件要更改,但是当我推送到 Heroku 时,那个文件的更改不存在……但对于大多数文件,更改都存在……

但如果我这样做

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

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

4

6 回答 6

114

文档

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

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

于 2013-11-09T15:54:45.270 回答
30

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
于 2018-04-20T13:15:29.370 回答
3

它们之间的基本区别在于:

 git commit -m = send log message (don't work without git add )
 git commit -am = git add -a + git commit -m

和 git add -a = 阶段一切

于 2021-10-28T14:03:52.273 回答
1

git commit -m "first commit" 和 git commit -am "your first commit" 之间的区别在于,在前者中,您需要先执行“git add”。而你在后者中不需要它。“-am”标志中的“a”告诉 git 首先添加所有更改

于 2021-06-02T10:43:43.007 回答
0

git commit -am是为 TRACKED(=STAGED) 文件一次暂存和提交的便捷命令。

正如钉子回答的那样,

git commit -am = git commit -a + git commit -m 

git commit -m: commit with message (你可能知道这部分)

git commit -a| git commit --all

告诉命令自动暂存已修改和删除的文件,但未告诉 Git 的新文件不受影响。-来自 git 文档

你没有告诉 Git 的新文件不受影响

粗体部分是重要的。

-am标志仅适用于已修改或删除的TRACKED(暂存)文件(b/c“删除”表示删除存在的内容 = 之前跟踪的内容)

因此,如果您添加新文件并使用-am标志提交,那些新创建的文件将不会包含在提交中,因为它没有被跟踪(暂存)。

如果您创建新文件并想使用-am标志来避免使用

git add .
git commit -m "some commit" // reducing one line makes a big difference, I agree

,首先使用这些新的git add .,您可以使用git commit -am上面两行的命令代替。

于 2022-02-15T03:41:28.317 回答
-1

它一起做 2 项工作 1)暂存修改后的文件 2)在同一行添加注释

但它不会将文件从 unstage 添加到 stage ,即它无法完成 $git add 的工作。

于 2021-07-19T14:20:11.840 回答