在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 rebase /my_remote_branch_name

其他回答

在我的情况下,我只是简单地这样做:

git pull --rebase

我能够在本地分支上获得所有远程更改。

谢谢。

上面已经提到了一些很好的答案,但如果你觉得困惑,你可以试试这个(警告:如果你有本地更改,下面的命令将擦除更改):

git reset --hard origin/<remote_branch_name>

示例:如果分支名称为master

git reset --hard origin/master

该命令将丢弃任何本地分支更改,并使您的本地分支与远程分支完全相同。换句话说,它使您的本地分支成为远程分支的副本。

Git配置拉。仅Ff或等价于git pull, Ff -only是最安全的。原因是,如果另一个开发人员强制推送到同一个分支,那么rebase可能会覆盖历史记录,并可能导致提交丢失。

但它们都是有效的。

这对我很有用。

git reset --hard origin/<remote_branch_name>

如果你正在使用Visual Studio的Git(2019年或2022年),并且开始遇到这个问题,那么你可以从Git选项卡->设置中定义这个选项。

拉拔时重新调整局部分支

如果您想要分支“合并”更改,则设置为false;如果您想要“重新基底”更改,则设置为True。