发布于 4年前

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.

基于上面说明,merge 选项必须写在 fetch 选项前面。而 --stat 是 git merge/git rebase 的选项,--no-tags 是 git fetch 的选项。所以当 --stat 选项写在 --no-tags 选项后面时,git pull 会报错,它应该是把 --stat 选项传给 git fetch 命令处理,但是 git fetch 命令没有这个选项,导致报错提示 "unknown option"。

git
©2020 edoou.com   京ICP备16001874号-3