在《Pro Git》引用格式推送這節中出現 fatal: invalid refspec ' topic:refs/remotes/origin/topic' 報錯

出現的問題

在《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 命令用來分割參數的分割符。下面是正確的操作示範

  1. 如果輸入命令時不想換行,輸入的時候把 \ 去掉,如下
    git fetch origin master:refs/remotes/origin/mymaster topic:refs/remotes/origin/topic
    
  2. 如果輸入命令時覺得命令太長,想換行,就可以先輸入
    git fetch origin master:refs/remotes/origin/mymaster \
    
    按下 Enter 鍵,換行繼續輸入
    topic:refs/remotes/origin/topic
    

用以上兩種中任意一個輸入方式,就可以得到書中一樣的結果了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章