【问题标题】:Difference between git pull --rebase and git pull --ff-onlygit pull --rebase 和 git pull --ff-only 的区别
【发布时间】:2014-10-15 08:07:48
【问题描述】:

假设origin/master 提交A--B--C 而我的local/master 提交A--B--D

如果我使用git pull --rebase 会发生什么?

如果我使用git pull --ff-only 会发生什么?

生成的提交树有什么不同吗?

【问题讨论】:

    标签: git git-rebase git-pull


    【解决方案1】:

    如果我使用 git pull --rebase 会发生什么?

    git pull --rebase 大致相当于

    git fetch
    git rebase origin/master
    

    即您的远程更改 (C) 将在本地更改 (D) 之前应用,从而生成以下树

    A -- B -- C -- D
    

    如果我使用 git pull --ff-only 会发生什么?

    它会失败。

    git pull --ff-only对应

    git fetch
    git merge --ff-only origin/master
    

    --ff-only 仅在可以快进时应用远程更改。来自男人:

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

    由于您的本地和远程分支已经分歧,它们无法通过快进解决,git pull --ff-only 会失败。

    【讨论】:

    • 如果本地更改中没有提交 D 会发生什么?两个命令是否等效?
    • 是的,它们都会导致A--B--C
    • git pull --rebase --ff-only 会做什么? (假设有C&D)
    • IIRC --ff-only 选项在与 --rebase 配对时会被忽略
    • @BreakingBenjamin 如果您想保证线性历史,这很有用。默认情况下,pull 可以引入合并提交,而您可能更喜欢仅使用 rebase 和 ff。
    猜你喜欢
    • 2020-10-20
    • 2015-10-11
    • 2021-02-05
    • 2018-03-05
    • 2011-03-22
    • 2015-03-21
    • 2016-05-19
    • 2011-09-11
    相关资源
    最近更新 更多