详解执行 git pull 时是否打印改动的文件信息

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

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 命令会打印改动的文件信息,如今想要确认出现这种差别的缘由。android

通过排查,这是由于 git pull 执行的是 git rebase 所引发。
在git仓库目录下执行 git config -l 命令,看到有以下配置:git

pull.rebase=truebash

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

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

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

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

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

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

-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

相关文章
相关标签/搜索