在git拉origin master之后,我得到了以下消息:

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.

remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), 51.49 KiB | 850.00 KiB/s, done.

拉动似乎成功了,但我不确定。

我该怎么补救呢?


当前回答

我一直在用——ff-only得到错误,所以我只是创建了一个与远程分支同步的新分支:

跳到另一根树枝上:

git checkout -b other-branch

更改它的名称,这样它就不会打扰你:

git branch -m myBranch broken-myBranch

签出你想要同步的远程分支:

git checkout origin/myBranch

为它创建一个本地分支:

git checkout -b myBranch

将远程分支连接到您的:

--set-upstream-to=origin/myBranch myBranch

其他回答

这对我很有用。

git reset --hard origin/<remote_branch_name>

这意味着您的本地主服务器和远程主服务器已经出现了分歧,这意味着它们都有不能简单地快进的贡献。 为了保持你的本地提交,你可以遵循以下步骤:

1. git switch -C feature_branch (from master, create local branch with your local commits)
2. git switch master
3. git reset --hard origin/master (lose all local changes, and become same as origin/master)
4. git switch feature_branch
5. git merge master (add remote changes to your local)
6. git push
7. Make a pull request for master.

最安全的选择是只在全球范围内设置。运行:

git config --global pull.ff only

该选项将被添加到全局的.gitconfig中。

[pull]
    ff = only

如果快进后期失败,尝试git pull -no-ff。

Git配置拉。变基假

合并(默认策略)

哇,这里有很多好答案。 但我想从路线原因的角度来回答…

不容易确定OP路径,因为每个人都可能不同。 解决问题很好,但首先预防问题就更好了。 尽管我尊重上面的答案,因为他们的知识远比我多。

这是我的问题的原因,与上面的错误相同:

做一个提交和推拉从我的开发分支到我的远程开发分支(使用VS Code); 然后是我团队分公司的公关。 然后在github中,我将我的团队分支合并到我的开发分支中(更高),以使开发与其他团队保持一致,以确保我们所有人都一致。 第二天早上,我做了一个新的提交,但是当我在我的本地上使用Push/Pull in VS Oce时,我得到了错误。

我应该做的是我在远程合并后,我应该拉或获取远程到我的本地之前做进一步的改变,然后我就不会得到错误。

所以我的日常生活应该改变,当我合并团队到Dev在我的遥控器上,我也必须把它拉到本地直接

我还有另一个复合因素,我的新提交与合并到我的Dev分支的冲突,所以我收到了不同的错误,告诉我在Pull之前删除或隐藏我的更改。

所以,如果把这个问题解决了,按正确的顺序来做也许就能在一开始就避免这个错误。(可能)。