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

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

$ git pull --no-tags --stat aosp remote_branch_name
error: unknown option `stat' 複製代碼

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

$ 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 的幫助說明,對此說明以下:app

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.fetch

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

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

相關文章
相關標籤/搜索