在bash函数承诺,推动在一个命令 [英] Function in bash to commit and push in one command
问题描述
我试着提交并推一个命令,键入类似:
I try to commit and push in one command, typing something like:
转基因这是我的提交信息
这将运行:
git的承诺-am这是我的提交信息&放大器;&安培;混帐推
我试过这个功能我的.bashrc
:
function gm() {
git commit -am $1 && git push
}
其中一期工程,除了我不能键入几个单词作为提交信息的事实。我可以运行
Which works, except for the fact that I can not type several words as commit message. I can run
转My_Message
和它工作正常,但如果我输入几个单词,像
and it works fine, but if I type several words, like
转基因这是我的消息
这将只运行 git的承诺-am这与&&安培;混帐推
。我试着用引号但它返回一个错误。我应该如何配置此功能工作?
It will only run git commit -am "This" && git push
. I tried using quotation marks but it returns an error. How should I configure this function to work?
推荐答案
您需要两个左右的地方报价调用该函数和git的命令。
You need quotes around both the place calling the function and the git command.
function gm() {
git commit -am "$1" && git push
}
gm "This is my message"
另一种方法是:
function gm() {
git commit -am "$*" && git push
}
gm This is my message
但是,这将意味着:
But this will mean that:
gm This commit has double spaced sections.\t And a tab, \
and a new line
(凡\\ t实际上是一个标签)结果
会给提交信息:
(Where \t is actually a tab)
will give the commit message of:
This commit has double spaced sections. And a tab, and a new line
因此,所有的空格已展开。
So all the white space is collapsed.
另外,如果你想进入一个更为复杂和完整的提交信息,您可能希望你 $ EDITOR
并省略 -m
完全
Also, if you want to enter a more complicated and complete commit message, you might want to you $EDITOR
and omit -m
entirely.
另外,你是不是真的使用分布式版本控制,如果你马上推每次提交的力量。
Also, you aren't really using the power of distributed version control if you immediately push every commit.
这篇关于在bash函数承诺,推动在一个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!