跳至主要内容

Git warning: Pulling without specifying how to reconcile divergent branches is discouraged

 原文链接

As of Git version 2.27.0 running the command git pull will display the following message unless your Git configuration includes certain settings.

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:

  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.

Short Explanation

Git wants us to choose how it should handle the situation where our remote branch (e.g. origin/develop) is out of sync with our local branch (develop). Many people (myself included) feel the default way Git historically handled this situation was sub-optimal however changing the default behavior is a big deal. Instead Git has made it easy to modify the behavior and added this screen to remind you that you might want to change the default.

Short Fix

The short answer is yes, we do want to change the default behavior and we can do that by running the following from the command line.

git config --global pull.ff only

This will add a line to your global Git configuration file to use the “best” approach when using git pull.

The Problem We are Solving

When working with Git you have your local branch on your computer (e.g. develop) and your remote branch (e.g. origin/develop). Your remote branch typically lives somewhere like GitHub.

You’d like to have the same commits on your local branch and your remote branch, so it looks something like this.

develop    origin/develop

cem32k     cem32k
b4d2o1     b4d2o1
abc123     abc123

(If viewing your Git branch as a list of commits like this seems unfamiliar, I suggest checking out my post on How to Improve Git Log)

Someone Else Adds a Commit

When someone else uses git push to add their commit (e.g. zyx911) to origin/develop, we get out of sync.

develop    origin/develop

           zyx911
cem32k     cem32k
b4d2o1     b4d2o1
abc123     abc123

The good news is we can bring things back in sync by running git pull. In this case, it is obvious to Git that by adding zyx911 to our commits, we’ll be in sync. This is called a fast-forward merge.

develop    origin/develop

zyx911     zyx911
cem32k     cem32k
b4d2o1     b4d2o1
abc123     abc123

The command we added above (git config --global pull.ff only) sets this to be the only kind of merge that Git should do unless we explicitly tell it otherwise.

Both Add a Commit

Imagine the situation where someone else adds a commit to the remote branch (e.g. zyx911 gets added to origin/develop) and at the same time we add a commit to our local branch (e.g. we add dg34mp to develop).

develop    origin/develop

dg34mp     zyx911
cem32k     cem32k
b4d2o1     b4d2o1
abc123     abc123

Now when we run git pull Git says, “Whoa, hold on! I can’t add the zyx911 commit to our local branch because there is an extra commit on our local branch that doesn’t exist on the remote branch!” (a.k.a. I don’t know how to handle zyx911).

Note: This is the same situation I discuss in Git failed to push some refs.

Three Ways to Handle the Situation

Create a Merge Commit

This is the historical default behavior. Git creates a new commit (e.g. 3649fc) which is a parent to both dg34mp and zyx911. Merge commits are a tremendously useful tool in Git, however they also bring with them complexity, which is why most agree that Git should not create a merge commit without the user explicitly requesting it.

Additionally, because we are merging these to different commits this is a common time to have merge conflicts.

    develop       origin/develop

    3649fc
dg34mp  zyx911    zyx911
    cem32k        cem32k
    b4d2o1        b4d2o1
    abc123        abc123

Rebase our Local Commits

Rebasing is an important Git idea that deserves an entire post of its own but in broad strokes:

Rebasing takes our local commit (dg34mp) and temporarily removes it from our local branch, which makes it an easy fast-forward merge

develop    origin/develop

zyx911     zyx911
cem32k     cem32k
b4d2o1     b4d2o1
abc123     abc123

then our commit (dg34mp) is added back to our local branch

develop         origin/develop

40931 (dg34mp)
zyx911          zyx911
cem32k          cem32k
b4d2o1          b4d2o1
abc123          abc123

however because the commit hash (dg34mp) is based on not only our changes but all the changes before it, the commit hash changes (here to 40931). This is also a time that merge conflicts are common.

Don’t Do Anything By Default

Since both creating a merge conflict and rebasing have their own complexities, we don’t want Git to do either by default. This is why we set fast-forward only with git config --global pull.ff. As long as we are only pulling in new commits, git pull works fine but if things get out of sync we get the message

fatal: Not possible to fast-forward, aborting.

Then we can explicitly tell Git to rebase our changes

git pull --rebase

or create a merge commit

git pull -c pull.ff=false pull

Instead of explicitly creating a merge commit with git pull -c pull.ff=false pull, we alternatively we could do a git fetch followed by git merge origin/<branchname>.

Global Git Configuration

When we run git config --global pull.ff only it adds the following

[pull]
        ff = only

to our global Git configuration, typically found at ~/.gitconfig.

评论

此博客中的热门博文

Resolving errSecInternalComponent errors during code signing

原文链接 One code signing issue I commonly see, both here on DevForums and in my Day Job™ with DTS, is that the codesign command fails with errSecInternalComponent. This issue crops up in a wide variety of circumstances and the correct fix depends on the specific problem. This post is my attempt to clarify the potential causes of this error and help folks resolve it. If you have any questions or comments about this, please start a new thread, tagging it with Code Signing so that I see it. Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = "eskimo" + "1" + "@" + "apple.com" Resolving errSecInternalComponent errors during code signing In some circumstances the codesign command might fail with the error errSecInternalComponent. For example: % codesign -s "Apple Development" "MyTrue" MyTrue: errSecInternalComponent This typically affects folks who are signing code in a nonstandard environm...

iOS:检测使用VPN或Proxy

参考链接: https://www.jianshu.com/p/c3b950dbf86a https://gist.github.com/PramodJoshi/4faad4c91f7dcb4eb9b06be8390c01db http://noodlecode.net/2018/04/check-if-ios-app-is-connected-to-vpn 第一种方法 需要导入框架CFNetwork 然后,这个方法是mrc的:需要添加-fno-objc-arc的flag 代码如下: + ( BOOL )getProxyStatus { NSDictionary *proxySettings = NSMakeCollectable ([( NSDictionary *) CFNetworkCopySystemProxySettings () autorelease]); NSArray *proxies = NSMakeCollectable ([( NSArray *) CFNetworkCopyProxiesForURL (( CFURLRef )[ NSURL URLWithString: @"http://www.google.com" ], ( CFDictionaryRef )proxySettings) autorelease]); NSDictionary *settings = [proxies objectAtIndex: 0 ]; NSLog ( @"host=%@" , [settings objectForKey:( NSString *)kCFProxyHostNameKey]); NSLog ( @"port=%@" , [settings objectForKey:( NSString *)kCFProxyPortNumberKey]); NSLog ( @"type=%@" , [settings objectForKey:( NSString *)kCFProxyTypeKey]); if ([[settings object...

去广告DNS设置,国内ADGuard DNS方案,手机电脑iOS去广告,保护隐私

 原文链接 之前分享过使用mac系统搭建adguard home,这几个月用下来零零散散基本上也被弃用了。主要原因是因为需要保持电脑一直开机。但是我的电脑是笔记本,存在移动各个地域的情况,也就是说只能够屏蔽电脑自身,对于手机而言不太现实。今天偶然发现dnspod推出了高级版的公共解析。dnspod背靠腾讯云,肯定是合法合规的公共解析服务,这个高级版用起来不错。 国内自己搭建解析服务是违法行为,所以这也是为什么使用dnspod的原因。 后台截图 开始使用 首先我们先进入dnspod的公共解析页面,点击开始使用。 专业版公共解析 dnspod会提供几种预设,我们选择「开发者」即可 开发者 然后你就成功的申请到自己个人使用的dns了! 更新拦截规则 我们可以将常见的广告过滤规则加入到dns中。我们在顶部选项卡中选择「拦截规则」。 拦截规则设置 打开adguard adguard 绑定iOS设备 推荐使用描述文件的方式,删除配置时删除描述文件即可。 描述文件 绑定macOS 推荐使用描述文件的方式,删除配置时删除描述文件即可。 描述文件 mac需要在「系统偏好设置」的「网络」中查看是否正在运行。 代理 如果没有运行需要点击「···」来启动服务。 启动服务 绑定路由器 找到自己路由器的DHCP设置,修改dns,然后记得绑定自己的ip。 修改dns 绑定ip 费用 目前有300万次/月的免费额度,但没有超出之后的价格。300万次一个人比较难用完,可以放心使用。 我个人使用iOS设备两台、智能家居、电脑两台,日均请求数大致2万/日。 判断是否搭建成功 可以通过查看日志的方式,日志大概有半小时到一小时的延迟,请耐心等待。