【问题标题】:I would like to use simple git merge instead of git rebase, which are the differences?我想使用简单的 git merge 而不是 git rebase,有什么区别?
【发布时间】:2021-06-06 01:46:39
【问题描述】:

在我执行git pull upstream master 命令后,“git”建议我先解决冲突,然后是git add file,然后是git rebase --continue

但是,我不想使用 git rebase,我更喜欢 git merge,它对我来说似乎更干净。 有什么建议吗?

【问题讨论】:

  • Git 只会在你之前开始 rebase 时建议continuing rebase。如果您的 Git 不是太古老,git status 还会告诉您,如果您处于不完整的 rebase(或合并)中间,那么您正处于不完整的 rebase(或合并)中间。您可能已经运行了一个您忘记的git rebase,或者因为您通过运行git pullpull 的第二个操作设置为rebase 来运行它。
  • 无论如何,是的,您可以使用git rebase --abort 来终止正在进行的变基并将一切恢复到开始之前的状态。不过,最好弄清楚你是如何开始使用 rebase 的。
  • "Merge" 和 "rebase" 是不同的命令。不要混合它们。 Git无法解决冲突,需要人工干预。这就是冲突的定义:不能自动合并的两个分支上的更改。
  • 运行 git --version 以了解您安装的 Git 有多古老。如果它在 Git 2.17 左右之前,它已经很老了。当前的 Git 是 2.30,“现代”此时大约是 2.23 左右。
  • 2.29.2 抱歉我已经编辑了我的帖子,因为首先我做了一个 git pull,而不是一个 git merge,我认为这就是问题,因为 git 建议我(自动它) git rebase (git rebase --continue 等等)。另一方面,我只记得我做了 git pull 因为当我做 git merge upstream master 时,git 说我已经全部更新了,但事实并非如此,upstream 和 master 之间存在一些差异,这是因为我做了一个 git pull upstream master(我的 fork master)。

标签: git git-merge rebase


【解决方案1】:

看起来您的 git 配置告诉在拉取时使用 rebase,这可以解释为什么您的 git pull 开始使用 rebase 而不是 merge


  • 要停止当前的rebase 并改用merge,您可以运行:
git rebase --abort         # aborts the rebase, and resets to the original commit
git merge origin/mybranch  # merge the remote branch
  • 如果您想检查您的 pull 设置,请运行:
git config --show-origin --get pull.rebase

# if you see that the setting is global, and you want to drop it :
git config --global --unset pull.rebase
# if you want to disable it just on that local repository :
git config pull.rebase false
  • 您也可以保持pull 设置不变,并使用fetch,后跟mergerebase
git fetch

# after inspecting the remote, run either :
git merge @{u}
# or
git rebase @{u}

# '@{u}' is a shortcut for "the upstream branch of the current branch"

【讨论】:

  • 是的,我也猜到了。
  • 谢谢,git pull 配置对我很有用。
猜你喜欢
  • 2013-05-15
  • 1970-01-01
  • 2018-03-05
  • 2023-04-03
  • 2018-04-28
  • 2015-03-21
  • 2012-06-28
  • 2012-02-22
相关资源
最近更新 更多