Git 命令提交所有更改,包括删除或创建的文件

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

Git command to commit all changes including files removed or created

gitgithub

提问by Gabriel

After making changes to files already tracked by gitI usually do a:

在对已被跟踪的文件进行更改后,git我通常会执行以下操作:

git commit -a -m "a message describing what you did"

followed by

其次是

git push origin master

to commit and then push all changes to my Github account. The first command however does not work for commiting files either added or removed. To do that I would have to first type:

提交然后将所有更改推送到我的 Github 帐户。然而,第一个命令不适用于提交添加或删除的文件。为此,我必须首先输入:

git add -A

as mentioned here: How to commit and push all changes, including deletes?.

如此处所述:如何提交和推送所有更改,包括删除?.

In this other question Git commit all files using single commandthe accepted answer indicates that the only way to apply the fullcommit (ie: including files added or removed, not only edited) and then the push is by combining them with the &&command like so:

在另一个问题中,Git commit all files using single command接受的答案表明应用完整提交的唯一方法(即:包括添加或删除的文件,不仅是编辑的文件)然后推送是通过将它们与这样的&&命令组合:

git add -A && git commit

which in my case would look like:

在我的情况下,它看起来像:

git add -A && git commit -a -m "a message describing what you did" && git push origin master

Now for the question(s): is this large command correct? Is there a way to create a new gitcommand to apply these three commands all at once? Furthermore: is this merging of commands recommended or discouraged? If so, please state the reason.

现在的问题是:这个大命令正确吗?有没有办法创建一个新git命令来同时应用这三个命令?此外:建议还是不鼓励这种命令合并?如果是,请说明原因。



Edit

编辑

I immediately regret this decision: Edit last pushed commit's message.

我立即后悔这个决定:编辑上次推送提交的消息

回答by jacob1123

Looks correct to me.

对我来说看起来是正确的。

You could create an alias for the command by executing

您可以通过执行为命令创建别名

git config --global alias.commitall '!func(){ git add -A && git commit -am "" && git push origin HEAD; }; func'

Then you could commit all changes by entering

然后你可以通过输入提交所有更改

git commitall "a message describing what you did"

回答by Stoic

Yeah. That large command is actually correct. It will allow you to commit everything inside a given directory in a repo, including newly created / untracked files.

是的。那个大命令实际上是正确的。它将允许您提交存储库中给定目录中的所有内容,包括新创建的/未跟踪的文件。

Yes, you can create a new gitcommand (actually, an alias) like this:

是的,您可以git像这样创建一个新命令(实际上是一个别名):

[alias]
acp = "!f(){ git add -A && git commit -am "" && git push origin master; };f"

The above alias must go inside your global git configuration (at ~/.gitconfig) under section labelled [alias]. Now, you can write something like: git acp <message>to run the above command.

上述别名必须位于~/.gitconfig标记为 的部分下的全局 git 配置 (at ) 中[alias]。现在,您可以编写如下内容:git acp <message>运行上述命令。

Merging of commands is definitely recommended and is the power that *nix provides. However, in the current case, make sure that you actually want to perform all these actions in a single step. Git assumes that you want to selectively add your changes.

绝对推荐合并命令,这是 *nix 提供的强大功能。但是,在当前情况下,请确保您确实希望在一个步骤中执行所有这些操作。Git 假定您希望有选择地添加更改。

回答by Kush

If you feel bad about typing three lines again and again, you could also use GUI tools. http://www.git-scm.com/downloads/guisBy the way, as "Stonic" said, you could always create a new git command.

如果您对一遍又一遍地键入三行感到不舒服,您也可以使用 GUI 工具。 http://www.git-scm.com/downloads/guis顺便说一句,正如“Stonic”所说,你总是可以创建一个新的 git 命令。