如何使用一个命令登台并提交所有文件,包括新添加的文件?
如何使用一个命令登台并提交所有文件,包括新添加的文件?
Answers:
是否
git add -A && git commit -m "Your Message"
算作“单个命令”?
根据以下@thefinnomenon的答案进行编辑:
要将其作为git alias
,请使用:
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
不仅在工作树具有文件匹配的位置,而且在索引已经具有条目的位置,都更新索引。这将添加,修改和删除索引条目以匹配工作树。
如果
<pathspec>
在使用-A选项时未指定任何值,则将更新整个工作树中的所有文件(旧版本的Git用于将更新限制为当前目录及其子目录)。
git add -A ; git commit -m "Your Message"
该命令将添加并提交所有修改的文件,而不是新创建的文件。
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.
我使用此功能:
gcaa() { git add --all && git commit -m "$*" }
在我的zsh配置文件中,所以我可以这样做:
> gcaa This is the commit message
自动登台并提交所有文件。
function gcaa() { git add --all && git commit -m "$*" && git push }
gaa && gc -m "my commit"
但是这样好得多... <
一站式管理所有文件(Modify,Deleted和new)并提交注释:
git add --all && git commit -m "comment"
http://git-scm.com/docs/git-add
http://git-scm.com/docs/git-commit
我的配置中有两个别名:
alias.foo=commit -a -m 'none'
alias.coa=commit -a -m
如果我太懒了,我只需提交所有更改
git foo
并做一个快速提交
git coa "my changes are..."
coa代表“全部提交”
运行给定的命令
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的相对误差级&&
IS||
当第一个命令不成功或错误级别为1时运行第二个命令。
或者,您可以将alise创建为git config --global alias.addcommit '!git add -a && git commit -m'
并将其用作git addcommit -m "Added and commited new files"
很好的答案,但是如果您想找到一条单线的方法,可以进行串联,别名并享受便利:
git add * && git commit -am "<commit message>"
它是一行,但是只有两个命令,并且如上所述,您可以为这些命令起别名:
alias git-aac="git add * && git commit -am "
(末尾的空格很重要),因为您将参数化新的简写命令。
从这一刻起,您将使用以下别名:
git-acc "<commit message>"
您基本上是说:
git,为我添加所有未跟踪的文件,并使用此给定的提交消息提交它们。
希望您使用Linux,希望对您有所帮助。