玖叶教程网

前端编程开发入门

为什么执行 git pull 没有输出改动的文件信息?

在公司的Android代码目录里面,使用 git pull 命令,发现不会输出发生改变的文件信息。例如不会打印类似下面的信息:

Fast-forward
 res/values-zh-rCN/strings.xml | 5 +++--
 res/values/strings.xml | 4 ++--
 src/com/android/SoftwarePreferenceController.java | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

但是之前公司的 git pull 命令会打印改动的文件信息,现在想要确认出现这种差异的原因。

经过排查,这是因为 git pull 执行的是 git rebase 所引起。

在git仓库目录下执行 git config -l 命令,看到有如下配置:

pull.rebase=true

这是当前代码目录的git仓库里面自行配置的。使用 git config --global -l 命令查看没有这个配置。

查看 man git-config 命令的说明,pull.rebase=true 表示 git pull 使用 git rebase,而不是使用 git merge:

pull.rebase

When true, rebase branches on top of the fetched branch, instead of merging the default branch from the default remote when "git pull" is run.

再查看 man git-rebase 命令的说明:

rebase.stat

Whether to show a diffstat of what changed upstream since the last rebase. False by default.

--stat

Show a diffstat of what changed upstream since the last rebase. The diffstat is also controlled by the configuration option rebase.stat.

-n, --no-stat

Do not show a diffstat as part of the rebase process.

即,git rebase 默认不会打印发生变动的文件名。如果想要打印,需要添加 --stat 选项。

作为对比,git merge 命令默认会打印修改前后的文件名。下面是 man git-merge 命令的说明:

--stat, -n, --no-stat

Show a diffstat at the end of the merge. The diffstat is also controlled by the configuration option merge.stat.

With -n or --no-stat do not show a diffstat at the end of the merge.

merge.stat

Whether to print the diffstat between ORIG_HEAD and the merge result at the end of the merge. True by default.

总的来说,git pull 命令其实是先使用 git fetch 获取远端代码,然后调用 git merge 把获取到的远端代码合并到本地分支。如果提供了 --rebase 选项,会用 git rebase 来替代 git merge。配置 pull.rebase 为true,git pull 默认会用 git rebase。

当 git pull 使用 git merge 时,默认会打印变动的文件信息。

而 git pull 使用 git rebase 时,默认不会打印变动的文件信息。

如果不确定使用的是 git merge、还是 git rebase,又想要每次执行 git pull 都能打印变动的文件信息,可以加上 `--stat` 选项,例如 `git pull --stat`。

发表评论:

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