【问题标题】:Difference between `git pull --rebase --autostash` and `git pull --ff-only`?`git pull --rebase --autostash` 和 `git pull --ff-only` 之间的区别?
【发布时间】:2020-10-20 20:54:01
【问题描述】:

以下问题Can “git pull” automatically stash and pop pending changes 有使用两者的解决方案:

  • git pull --rebase --autostash

  • git pull --ff-only

我有点困惑我应该使用哪一个。他们真的完成了同样的结果吗?非常相似的question被问到哪个没有--autostash参数以及--rebase

【问题讨论】:

  • git pull --ff-only 只有在本地或远程发生变化时才能成功,如果本地和远程都有提交,则会触发错误。

标签: git git-rebase git-pull


【解决方案1】:

想象一下遥控器有你没有改变的情况:

remote | A - B - C - D - E
       |
local  | A - B - C

您可以在这里git pull --ff-only,因为可以从C 快进到E。现在假设您也进行了更改:

remote | A - B - C - D - E
       |
local  | A - B - C - F - G

如果你git pull --ff-only会被拒绝,因为你不能从G快进到E;每the docs(强调我的):

使用--ff-only,尽可能将合并解析为快进。 如果不可能,拒绝合并并以非零状态退出。

有两种方法可以解决这个问题:

  • 创建一个合并提交(默认的,如果快进是不可能的,或者可以用--no-ff强制);或
  • 变基 (--rebase)。

如果您git pull --rebase,它会将您的本地副本回滚到C,快进到E,然后将FG 重播到新的父级,离开:

remote | A - B - C - D - E
       |
local  | A - B - C - D - E - F' - G'

--autostash 是一个单独的 参数,根据the docs

这意味着您可以在脏工作树上运行操作。

在上述两种情况下,为了简单起见,我假设一个干净的工作树(即 git status 显示“没有提交,工作树干净” - 你没有未提交的本地更改),但有时你当您正在进行本地工作时,可能想要拉取新的更改。

【讨论】:

    猜你喜欢
    • 2014-10-15
    • 2020-08-24
    • 2021-02-05
    • 2015-10-11
    • 2018-03-05
    • 2021-10-14
    • 1970-01-01
    • 2011-03-22
    相关资源
    最近更新 更多