我正在尝试编写一个简单的shell脚本来简化git提交过程。
而不是
git add . -A
git commit -m "message"
git push我想做commit.sh "my commit message"
我现在拥有的是:
#!/bin/bash
commit_message="$1"
git add . -A
git commit -m $commit_message
git push这有两个问题:
error: pathspec 'commit' did not match any file(s) known to git.
error: pathspec 'message' did not match any file(s) known to git.
因此,它使用的提交消息的唯一部分是"my“,而其他”提交消息“则被排除在外。git add .引用的是shell脚本的位置,而不是当前的项目目录。如何使git add .引用我目前在终端中的位置?发布于 2013-07-29 17:52:39
您必须引用脚本中的变量。
#!/bin/bash -e
commit_message="$1"
git add . -A
git commit -m "$commit_message"
git push我还设置了"-e“,以便如果有任何错误,脚本将退出而无需处理后续命令。
至于您的第二个问题,脚本中的.应该按照您的意愿引用当前的工作目录。但是,-A导致它添加了在回购中修改过的所有文件。
发布于 2013-07-29 18:11:04
您可以创建带参数别名。类似于:
[alias]
  cap = "!git add . && git commit -m '$1' && git push origin"发布于 2014-02-19 01:26:45
使用和Alias,我不能将变量放在句子的中间,但是您可以创建一个函数并将其放在.bashrc上,如下所示
commit(){
  git add --all . && git commit -m '$1' && git push origin master
}https://stackoverflow.com/questions/17930725
复制相似问题