GIT多个命令在一行错误

时间:2018-05-08 09:38:31

标签: git macos shell

当我运行git add . & git commit -m "some fix" & git push时,它会返回错误:

<user> alexis$ git add . & git commit -m "Add some fix" & git push
[1] 32595
[2] 32596
fatal: Unable to
create'/Users/<user>/Desktop/project/.git/index.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
Everything up-to-date
[1]-  Done                    git add .
[2]+  Exit 128                git commit -m "Add some fix"

当我逐个执行所有cmd时,没有问题。

1 个答案:

答案 0 :(得分:2)

shell中的命令后单个&符号(&)表示在后台运行命令。从您的日志中,您可以查看作业/进程后台,这使命令可以并行运行

<user> alexis$ git add . & git commit -m "Add some fix" & git push
[1] 32595
[2] 32596

shell中的&&表示“逻辑AND”,||表示“逻辑OR”。你可以在很多启动/初始化脚本(如(jboss,tomcat)

)中找到明智的用法
[ -f "$file" ] && cat $file # cat the file only the file exists and regular file