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

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

我该怎么补救呢?


当前回答

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

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.

其他回答

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

拉拔时重新调整局部分支

如果您想要分支“合并”更改,则设置为false;如果您想要“重新基底”更改,则设置为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.

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

git pull --rebase

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

谢谢。

此问题在2.34.1中修复,更新Git版本。

这是Git 2.27中添加的一个新警告:

 * "git pull" issues a warning message until the pull.rebase
   configuration variable is explicitly given, which some existing
   users may find annoying---those who prefer not to rebase need to
   set the variable to false to squelch the warning.

要删除警告,如果你没有在命令行上指定行为(使用——ff,——no-ff,——ff-only,——rebase),将建议值之一设置为git拉取的首选默认行为。在所有情况下,如果可能的话,git都会尝试快进(什么是git快进?)这些设置控制在您的分支中发生更改但未在远程分支中显示时发生的情况。

  git config pull.rebase false  # merge (the default strategy)

这是现有的默认行为;设定为不发出警告,也不改变行为;Git会将远程分支合并到本地分支中。

  git config pull.rebase true   # rebase

在这里,git将尝试在远程分支的顶部重新基于您的更改。什么时候我应该使用git pull -rebase?关于你为什么想要那样做的更多细节。

  git config pull.ff only       # fast-forward only

如果快进合并是不可能的,git将拒绝继续。git pull -rebase和git pull -ff-only引号的区别:

拒绝合并并以非零状态退出,除非当前HEAD已经是最新的,或者合并可以作为快进解决