玖叶教程网

前端编程开发入门

git pull命令使用实例(git pull的用法)

在使用 git pull 命令拉取服务器代码时,不同的需求会有不同的用法。具体说明一些使用实例如下。

只拉取当前branch的信息

执行 git pull 命令默认会拉取远端服务器上的改动、以及各个 branch 和 tag 的信息。当远端服务器上有新增的 branch 或 tag,就会拉取到,并打印出来,有时候会打印很多这些信息。

如果想要只拉取当前 branch 的信息,需要加上远端服务器的仓库名和分支名作为参数。例如,将远端服务器 origin 仓库的 master 分支合并到本地当前 branch,可以执行下面的命令:

注意:这里的分支名是要拉取的远端服务器分支名,不是本地的分支名。

如果还要不拉取 tag 信息,可以再加上 --no-tags 选项:

使用这种方法更新代码,即使远端服务器上有新增的 branch,在本地执行 git branch -r 命令也不会看到新增的 branch。

在 bash 上输入时,可以使用 Tab 键来自动补全远端服务器仓库名,输入远端服务器仓库名后,再继续使用 Tab 键来提示要拉取的远端服务器分支名。

git pull 命令的选项顺序导致报错问题

实际使用 git pull 的时候,遇到这样一个问题,当把 --stat 选项写在 --no-tags 选项后面时,执行会报错:

但是把 --stat 选项和 --no-tags 选项的顺序调换,再执行 git pull 命令就不会报错:

即,--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.

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

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言