Git命令提交所有更改,包括已删除或创建的文件 [英] Git command to commit all changes including files removed or created
问题描述
更改已经由 git
跟踪的文件后,我通常会执行以下操作:
git commit -a -m一条描述你做了什么的消息
后面跟着
git push origin master
提交,然后将所有更改推送到我的Github帐户。然而,第一条命令不适用于提交或删除文件。要做到这一点,我必须先输入:
git add -A
如下所述:如何提交和推送所有更改,包括删除?。
在这个其他问题使用单个命令提交所有文件接受的答案表明应用完整提交(即:包括添加或删除的文件,不仅可以编辑),然后推送将它们与&&
命令相组合:
git add -A&&在我的情况下,git commit
git add -A&& git commit -a -m一条描述你做了什么的消息&& git push origin master
现在对于这个问题:这个大命令是否正确?有没有办法创建一个新的 git
命令来同时应用这三个命令?此外:这是合并推荐或劝阻的命令吗?如果是这样,请说明原因。
编辑
我立即后悔这个决定:编辑上次推送提交的消息。
您可以为该命令创建一个别名,方法是执行
git config --global alias.commitall'!func(){git add -A&& git commit -am$ 1&& git push origin HEAD; }; func'
然后您可以通过输入
git commitall一条描述你做了什么的消息
After making changes to files already tracked by git
I usually do a:
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:
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 command the accepted answer indicates that the only way to apply the full commit (ie: including files added or removed, not only edited) and then the push is by combining them with the &&
command like so:
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 git
command to apply these three commands all at once? Furthermore: is this merging of commands recommended or discouraged? If so, please state the reason.
Edit
I immediately regret this decision: Edit last pushed commit's message.
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 "$1" && git push origin HEAD; }; func'
Then you could commit all changes by entering
git commitall "a message describing what you did"
这篇关于Git命令提交所有更改,包括已删除或创建的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!