# 一、报错信息分析
| warning: Pulling without specifying how to reconcile divergent branches is discouraged. You can squelch this message by running one of the following commands sometime before your next pull: | |
| // 不鼓励在没有说明如何解决分歧分支的情况下进行pull。你可以在下一次pull之前运行以下命令之一来平息此消息: | |
| git config pull.rebase false # merge (the default strategy) // 缺省策略 | |
| git config pull.rebase true # rebase // 变基 | |
| git config pull.ff only # fast-forward only // 仅快进 | |
| You can replace "git config" with "git config --global" to set a default preference for all repositories. You can also pass --rebase, --no-rebase, or --ff-only on the command line to override the configured default per invocation. | |
| // 您可以将 "git config" 替换为 "git config --global" 以便为所有仓库设置缺省的配置项。 | |
| // 也可以在每次执行 pull 命令时添加 --rebase、--no-rebase,或者 --ff-only 参数覆盖缺省设置。 | 
这个报警表示,你和你的同事在同一个分支上开发,当你的同事提交代码后,你再执行 git pull,会先将你同事的代码与你本地仓库的代码合并
这样当你 push 之后,你的 git 上会出现一个很烦人的 commit
例如下面这个:

# 二、命令介绍
# 1.git config
使用该命令来配置 git 的配置文件
- 仓库级别 local 【优先级最高】 
- 用户级别 global【优先级次之】 
- 系统级别 system【优先级最低】 - 系统级别,对应的配置文件是 git 安装目录下的 gitconfig 文件
 - 查看配置信息的命令 
| // 查看仓库配置 | |
| // 【必须要进入到具体的目录下,比如要查看TestGit仓库的配置信息】 | |
| git config --local -l  | |
| // 查看用户配置 | |
| git config --global -l  | |
| // 查看系统配置 | |
| git config --system -l  | |
| // 查看所有的配置信息,依次是系统级别、用户级别、仓库级别 | |
| git config -l | 
出现这种情况,多半是你本地的仓库落后于远程仓库很多个版本了
# 2.git pull warning 解析
git pull 为 git fetch + git merge FETCH_HEAD
# 1.pull.ff
ff === fast-forward
在我们开发代码时,都会将项目拆分为多个分支,在每个分支上处理不同的事物,当开发完不同的代码后,需要将分支进行合并,即 git merge ,而 merge 又分为两种:
# (1)fast-forward
一般情况下,git 默认使用 ff 来处理分支合并,当成功合并时,也不会产生任何提交记录,且当旧的分支被移除后,其分支信息也会被移除
例子:
| master---->ec5ba | |
| develop---->76b12 | |
| // 在master上合并dev | |
| $ git merge develop | |
| // 结果就是master分支上新增一个记录为develop 所在的记录,且最后成为当前最新记录【head指向当前记录】 | |
| master ----> 76b12<----develop | 

# (2)no-fast-forward
即在合并分支命令中加入 --no-ff 后缀方式进行运行,便会产生一个新的提交记录
例子:
| master ----> ec5ba | |
| develop ----> 76b12 | |
| // 在master上合并develop | |
| $ git merge develop --no-ff | |
| // master上生成一个新的提交记录,且该记录和develop及master都有联系 | |
| // 且develop上的原有记录保留 | |
| // 【head】指向master上生成的最新的提交记录 | 

此外,合并冲突时,在移除掉多余的代码后,也会产生一条新的提交记录,方式和 –-no-ff 大体一致

# 2.pull.rebase
衍合指定分支,变基,是 Git 整合变更的一种方式。
rebase 会把当前分支上的所有提交记录整合到指定分支上。
例:
| master ----> ec5ba | |
| develop ---->3a2e2 | |
| // 在develop分支上执行 | |
| $ git rebase master | |
| // 则将develop上的所有记录移到master记录的最顶端,变成一条线 | |
| // 且head指向develop的最新纪录 | 

# 3.only、true、false
# 1.only
| // only - 如果可能,拉动快进,否则操作将中止并显示错误消息。 | |
| git config pull.ff only | 
# 2.false
| // false - 使用默认行为 | |
| git config pull.rebase false | 
# 3.true
| // true - 使用命令修改 | |
| git config pull.rebase true | 
git config pull.rebase false的作用是设置 Git 在执行 git pull 命令时默认使用 merge 而不是 rebase。
git pull命令是将远程分支的更新合并到本地分支,如果本地分支有更新,则会自动执行合并操作。默认情况下,git pull命令会使用 rebase 的方式来合并分支。使用 rebase 的好处是可以保持提交历史的线性,避免了 merge 产生的分支合并记录。但是,如果在多人协作的项目中使用 rebase,可能会破坏提交历史,导致代码冲突,因此需要谨慎使用。
通过设置
git config pull.rebase false,Git 将默认使用 merge 的方式来合并分支,从而避免了 rebase 带来的潜在问题。需要注意的是,如果在执行 git pull 命令时指定了
--rebase选项,则 Git 会优先使用 rebase 的方式来合并分支,而不受git config pull.rebase的设置影响。因此,如果需要强制使用 merge 的方式来合并分支,可以在执行
git pull命令时添加--no-rebase选项。
# 三、报警分析
git 提供的三个命令提供了三种抑制警告的方法,但是用途不同:
# 1. git config pull.ff only
| // 即设置为 git fetch + git merge -ff,如果不能完成则会终止并显示错误 | |
| git config pull.ff only   // 仅快进合并 | 
# 2.git config pull.rebase false
| // 即 git fetch + git merge,保留默认行为且抑制警告 | |
| git config pull.rebase false //从远程上默认合并 | 
注意:
git config pull.rebase false
该命令所使用的合并跟随你的默认设置
如果,你设置了merge.ff false
不是默认的快速合并,而是创建一个记录进行合并
清除该设置后,默认为 - ff 快进合并。
# 3.git config pull.rebase true
| // 即 git fetch + git rebase | |
| git config pull.rebase true // 变基合并 | 
# 四、 解决方法
# 1. git warning 提供的是全局设置
| git config --global pull.rebase true | |
| // 这样当以后你执行 git pull 之后,都会按照变基处理。 | 
# 2. 单独设置,仅在此次 git 操作中使用
| git pull --rebase origin master | 
如果代码发生冲突后,此变基将会暂停,需要解决冲突后,再继续操作
| // 取消变基,Git 将您恢复为分支状态如同调用 git rebase 之前一样 | |
| git rebase --abord   | |
| // 冲突操作之后,继续完成变基 | |
| git rebase --continue | 
# 3. 直接入
综上,如果你不太承受变基合并带来的风险,也不清楚你的默认 merge 操作是什么的话,则可以使用
| git config pull.ff only | |
| // or | |
| git pull --ff-only | 
