如何使用单个命令对包括新添加的文件在内的所有文件进行暂存和提交?
如何使用单个命令对包括新添加的文件在内的所有文件进行暂存和提交?
这个问题是什么?
git add -A && git commit -m "Your Message"
算作“单个命令”吗?
要将其作为git别名
,请使用:
git config --global alias.coa "!git add -A && git commit -m"
提交所有文件,包括新文件,并带有一条消息进行提交:
git coa "A bunch of horrible changes"
从git add
文档中获取:
-A, --all, --no-ignore-removal
不仅在工作树中有匹配的文件,而且在索引中已经有条目的地方也更新索引。这将添加、修改和删除索引条目以匹配工作树。
如果使用 -A 选项时没有给出
<pathspec>
,则会更新整个工作树中的所有文件(旧版本的 Git 只会更新当前目录及其子目录)。
git add -A ; git commit -m "Your Message"
- Rafael Miceli这个命令将会添加并提交所有修改过的文件,但不会包括新创建的文件:
git commit -am "<commit message>"
根据 man git-commit
:
-a, --all
Tell the command to automatically stage files that have been modified
and deleted, but new files you have not told Git about are not
affected.
不确定为什么这些答案都没有直接给出我认为是正确解决方案的方法,不过就算这样,以下是我使用的方法:
git config --global alias.coa '!git add -A && git commit -m'
注意:在执行git add -A
命令之前需要加上!
,才能使其正常工作。您可以在这里阅读有关Git别名的更多信息:git-scm.com | 2.7 Git Basics - Git Aliases
git coa "A bunch of horrible changes"
注意:coa
是“全部提交”(commit all)的缩写,可以用自己喜欢的任何词汇替换。
我使用这个函数:
gcaa() { git add --all && git commit -m "$*" }
在我的zsh配置文件中,这样我就可以轻松地执行:> gcaa This is the commit message
自动暂存并提交所有文件。
function gcaa() {
git add --all && git commit -m "$*" && git push
}
- Damilolagit add --all && git commit -m "comment"
http://git-scm.com/docs/git-add
http://git-scm.com/docs/git-commit
This situation is where you have multiple file updated and wants to commit:
You have to add all the modified files before you commit anything.
git add -A
or
git add --all
After that you can use commit all the added files
git commit
with this you have to add the message for this commit.
git config --global alias.temp '!git add -A && git commit -m "Temp"'
git temp
,Git 就会自动将您的所有更改作为一个名为“Temp”的提交提交到当前分支。然后,您可以稍后使用git reset HEAD~
来“撤消”更改,以便继续工作,或使用git commit --amend
来添加更多更改并/或给它一个适当的名称。git add . && git commit -m "Changes Committed"
然而,即使看起来是一个单独的命令,它实际上是分成两个命令依次运行。在这里,我们只是使用&&
将它们组合起来。这与单独运行git add .
和git commit -m "Changes Committed"
没有太大区别。您可以一次运行多个命令,但顺序很重要。如果您想要将更改推送到远程服务器并将其暂存和提交,则可以按照以下方式执行:
git add . && git commit -m "Changes Committed" && git push origin master
push
放在第一位,它将首先执行,并且不会在暂存和提交后给出所需的推送,因为它已经先运行了。
&&
在第一个命令成功返回或错误级别为0时,在该行上运行第二个命令。与&&
相反的是||
,当第一个命令不成功或错误级别为1时,运行第二个命令。git config --global alias.addcommit'!git add -a && git commit -m'
,并将其用作git addcommit -m“添加并提交新文件”
。我在我的配置文件中有两个别名:
alias.foo=commit -a -m 'none'
alias.coa=commit -a -m
如果我太懒了,我就会使用以下命令提交所有更改:
git foo
只需快速提交即可
(这句话是关于IT技术的)git coa "my changes are..."
COA代表“提交全部”。
git add * && git commit -am "<commit message>"
这是一行代码,但是包含两个命令,正如前面提到的,你可以为这些命令取一个别名:
alias git-aac="git add * && git commit -am "
(末尾的空格很重要),因为你将为新的简写命令参数化。git-acc "<commit message>"
你基本上是在说: