0

SO I'm trying to setup this shortcut in bashrc to commtitting to git using the current branch name as the commit message and I have this:

git branch | grep "*" | sed "s/* //" | git commit -m

but running this line would instead display the

error: switch `m' requires a value

error....

how can I fix this such that executing this line will be equivalent to running git commit -m "CurrentBranchName"

4

1 回答 1

0
  • 您几乎就在那里,除了xargs, 因为消息需要作为命令行参数传递,而不是STDIN在使用-mto 选项时传递git commit

    git branch | grep "*" | sed "s/* //" | xargs git commit -m
    
  • 不使用也应该工作的替代方法xargs

    git branch | grep "*" | sed "s/* //" | git commit -F -
    

    -F指示git commit从文件中读取提交消息,并指示-该文件是 STDIN(即来自 的管道的输出sed)。

于 2013-04-30T21:18:06.840 回答