出现的问题
在《Pro Git》 — 引用格式推送 这一小节中,有下面的命令和输出结果
git fetch origin master:refs/remotes/origin/mymaster \
topic:refs/remotes/origin/topic
From [email protected]:schacon/simplegit
! [rejected] master -> origin/mymaster (non fast forward)
* [new branch] topic -> origin/topic
但是自己在终端输入
git fetch origin master:refs/remotes/origin/mymaster \ topic:refs/remotes/origin/topic
却并没有出现和上面一样的结果,而是输出如下错误
fatal: invalid refspec ' topic:refs/remotes/origin/topic'
解决的办法
因为在 shell 命令中 \
表示换行继续输入的意思,也就是当命令太长的时候,可以用 \
对命令进行分割,转为下一行继续输入,而并不是 git fetch
命令用来分割参数的分割符。下面是正确的操作示范
- 如果输入命令时不想换行,输入的时候把
去掉,如下\
git fetch origin master:refs/remotes/origin/mymaster topic:refs/remotes/origin/topic
- 如果输入命令时觉得命令太长,想换行,就可以先输入
git fetch origin master:refs/remotes/origin/mymaster \
按下 Enter 键,换行继续输入
topic:refs/remotes/origin/topic
用以上两种中任意一个输入方式,就可以得到书中一样的结果了。