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

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

我该怎么补救呢?


当前回答

这对我很有用。

git reset --hard origin/<remote_branch_name>

其他回答

这对我很有用

git config --global pull.ff true

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

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.

已经有很多答案了,但是,我的处理方式是 如果你想从分支A拉到分支B

我首先从a中创建一个pull request到let,比如master。 确保所有冲突都得到解决,并将A合并为master。 然后简单地从主分支拉入分支B。

让我们举个例子,你从开发分支创建了一个分支A,在从开发分支拉到分支A的过程中,出现了这个发散的问题。你不能把更新代码从开发到你的A分支。因此,请按照以下步骤解决此问题

Git签出开发分支(这将切换到开发分支) Git拉(它将拉所有的更改来开发) git checkout A-feature-branch(这将切换到你的feature branch) Git合并开发分支(它将合并所有更改到您的功能分支)

现在,您已经将代码从develop更新到本地分支。 享受你的编码:)

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

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

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

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

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

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

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

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