git pull 命令的選項順序導致執行報錯

實際使用 git pull 的時候,遇到這樣一個問題,當把 --stat 選項寫在 --no-tags 選項後面執行會報錯:

$ git pull --no-tags --stat aosp remote_branch_name
error: unknown option `stat'

但是把 --stat 選項和 --no-tags 選項的順序調換,再執行 git pull 命令就不會報錯:

$ git pull --stat --no-tags aosp remote_branch_name
From platform/packages/apps/Settings
 * branch            remote_branch_name -> FETCH_HEAD
Current branch remote_branch_name is up to date.

即,--stat 選項必須寫在 --no-tags 選項前面,否則 git pull 就會報錯。查看 man git-pull 的幫助說明,對此說明如下:

More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch. With --rebase, it runs git rebase instead of git merge.

Options meant for git pull itself and the underlying git merge must be given before the options meant for git fetch.

而 --stat 是 git merge/git rebase 的選項,--no-tags 是 git fetch 的選項。基於上面說明,merge 選項必須寫在 fetch 選項前面。所以當 --stat 選項寫在 --no-tags 選項後面時,git pull 會報錯,它應該是把 --stat 選項傳給 git fetch 命令處理,但是 git fetch 命令沒有這個選項,導致報錯提示 "unknown option"。

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