gpt4 book ai didi

git rebase 混淆

转载 作者:行者123 更新时间:2023-12-04 05:35:42 28 4
gpt4 key购买 nike

假设我有 2 个分支topicmaster如果我在 topic分支,然后运行 ​​git rebase master它是 rebase master 还是 rebase 主题分支?

git rebase --help给了我这个

假设存在以下历史记录并且当前分支是“主题”:

             A---B---C topic
/
D---E---F---G master

从这一点来看,以下任一命令的结果:
       git rebase master
git rebase master topic

将是:
                         A'--B'--C' topic
/
D---E---F---G master

注意:后一种形式只是 git checkout 主题的简写,然后是 git rebase master。当 rebase 退出时,主题将保持已 check out 的分支。

如果我想实现这个 D---E---F---G---A---B---C master , 我应该切换到 master 并运行 git rebase -i topic ?

如果我跑 git rebase -i topic尝试将 A、B、C 压缩为 C 以成为 D---E---F---G---C master , 我得到 noop

最佳答案

假设你从一棵看起来像这样的树开始

         A---B---C topic
/
D---E---F---G master

您需要运行 2 个命令 git rebase master让它看起来像这样
                     A'--B'--C' topic
/
D---E---F---G master

然后来自 master运行 git merge topic ,这将进行快进 merge ,您最终会得到一棵看起来像这样的树
                             topic
/
D---E---F---G---A---B---C -- master

Can I just checkout master and run git rebase topic??



运行该命令将产生一个看起来像这样的树
                             topic
/
D---A---B---C---E---F---G -- master

这是 rebase 的(稍微编辑过的)git 文档,希望这会有所帮助:

All changes made by commits in the current branch but that are not in upstream are saved to a temporary area.



如果您在 topic并运行 git rebase master ,这意味着提交 A、B 和 C 将进入临时区域。

The current branch is reset to upstream. This has the exact same effect as git reset --hard upstream.



此时树的临时状态是这样的
                 topic
/
D---E---F---G -- master

The commits that were previously saved into the temporary area are then reapplied to the current branch, one by one, in order.



保存到临时区域的提交 A、B、C 将“重新提交”到您当前所在的分支 topic .
                             topic
/
D---E---F---G---A---B---C -- master

运行 git rebase topic来自 master将执行完全相同的步骤,除了不是将提交 A、B、C 放入临时区域,而是将提交 E、F G 放入临时区域。

关于git rebase 混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11979414/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com