Git 添加和提交在一个命令中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4298960/
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
Git add and commit in one command
提问by Chetan
Is there any way I can do
有什么办法吗
git add -A
git commit -m "commit message"
in one command?
在一个命令中?
I seem to be doing those two commands a lot, and if Git had an option like git commit -Am "commit message"
, it would make life that much more convenient.
我似乎经常执行这两个命令,如果 Git 有一个类似 的选项git commit -Am "commit message"
,它会让生活变得更加方便。
git commit
has the -a
modifier, but it doesn't quite do the same as doing git add -A
before committing. git add -A
adds newly created files, but git commit -am
does not. What does?
git commit
有-a
修饰符,但它与git add -A
提交之前所做的并不完全相同。git add -A
添加新创建的文件,但git commit -am
不添加。有什么作用?
回答by Martin C.
You can use git aliases, e.g.
您可以使用 git 别名,例如
git config --global alias.add-commit '!git add -A && git commit'
and use it with
并使用它
git add-commit -m 'My commit message'
EDIT:Reverted back to ticks ('), as otherwise it will fail for shell expansion on Linux. On Windows, one should use use double-quotes (")instead (pointed out in the comments, did not verify).
编辑:恢复为刻度 ('),否则 Linux 上的 shell 扩展将失败。在 Windows 上,应该使用双引号 (")代替(在评论中指出,未验证)。
回答by Jed Schneider
git commit -am "message"
is an easy way to tell git to delete files you have deleted, but I generally don't recommend such catch-all workflows. Git commits should in best practice be fairly atomic and only affect a few files.
是告诉 git 删除您已删除的文件的简单方法,但我通常不推荐这种包罗万象的工作流程。在最佳实践中,Git 提交应该是相当原子的,并且只影响几个文件。
git add .
git commit -m "message"
is an easy way to add all files new or modified. Also, the catch-all qualification applies. The above commands will not delete files deleted without the git rm
command.
是添加所有新文件或修改文件的简单方法。此外,包罗万象的资格也适用。上述命令不会删除没有该git rm
命令删除的文件。
git add app
git commit -m "message"
is an easy way to add all files to the index from a single dir, in this case the app
dir.
是一种将所有文件从单个目录添加到索引的简单方法,在本例中为app
dir。
回答by Ales
To keep it in one line use:
要将其保持在一行中,请使用:
git add . && git commit -am "comment"
This line will add and commit all changed and added files to repository.
此行将添加并提交所有更改和添加的文件到存储库。
回答by Yarin
Just combine your commands:
只需结合您的命令:
git add -A && git commit -m "comment"
回答by danilo
Only adapting the Ales'sanswer and the courtsimas'scomment for linux bash:
仅调整Ales 的回答和Courtimas对linux bash的评论:
To keep it in one line use:
要将其保持在一行中,请使用:
git commit -am "comment"
git commit -am "comment"
This line will add and commit all changedto repository.
此行将添加并提交所有更改到存储库。
Just make sure there aren't new filesthat git hasn't picked up yet. otherwise you'll need to use:
只要确保没有git 尚未获取的新文件。否则你需要使用:
git add . ; git commit -am "message"
git add . ; git commit -am "message"
回答by sirwinny
In the later version of git you can add and commit like this
在更高版本的 git 中,您可以像这样添加和提交
git commit -a -m "commit message"
Additionally you an alias:
另外你一个别名:
[alias]
ac = commit -a -m
Then you can use it like this:
然后你可以像这样使用它:
git ac "commit message"
回答by Blair Anderson
pretty sure you can use:
很确定你可以使用:
git commit -am "commit all the things"
回答by Sojan V Jose
On my windows machine I have set up this .bashrc
alias to make the entire process more simple.
在我的 Windows 机器上,我设置了这个.bashrc
别名以使整个过程更加简单。
- create / locate your
.bashrc
- refer SO thread add the following line to file
alias gacp='echo "enter commit message : " && read MSG && git add . && git commit -m "$MSG" && git push'
it does git add commit and push . tweak it in any manner, say you don't want the push command remove that part
reload
.bashrc
/ close and reopen your shell- now you can do the entire process with
gacp
command .
- 创建/定位您的
.bashrc
- 参考 SO 线程 将以下行添加到文件中
alias gacp='echo "enter commit message : " && read MSG && git add . && git commit -m "$MSG" && git push'
它确实 git add commit 和 push 。以任何方式调整它,假设您不希望 push 命令删除该部分
重新加载
.bashrc
/关闭并重新打开您的外壳- 现在您可以使用
gacp
command完成整个过程。
回答by Navid Vafaei
If you type:
如果您键入:
git config --global alias.a '!git add -A && git commit -m'
once, you will just need to type
一次,您只需要输入
git a
every time:
每次:
git a 'your comment'
回答by Josh Olson
Just use:
只需使用:
git commit -m "message" .
Notice the "." at the end... which can also be a path to a file/directory
注意“.” 最后......也可以是文件/目录的路径