gpt4 book ai didi

git - 我如何使用 Git 作为一次提交 rebase

转载 作者:太空狗 更新时间:2023-10-29 13:18:37 27 4
gpt4 key购买 nike

我的历史看起来有点像这样但是乘以 10:

                i - j - e'- k - h'- l - m  feature-branch
/
a - b - c - d - e - f - g - h master

(撇号表示 cherry-pick )我想 rebase 到这个:

                                  i - j - k - l - m  feature-branch
/
a - b - c - d - e - f - g - h master

我不介意该功能是否被压缩为 1 次提交。常规 rebase 的主要问题是它试图一次 rebase 一个提交,我必须一遍又一遍地修复和重新修复类似的冲突。

我只想获取我的分支提示和主提示之间的差异,并将它们应用到主控之上。

最佳答案

这其实很简单。

  1. master merge 到 feature-branch 中。您将立即在这里解决所有 merge 冲突。 (我强烈建议停在这里。)

                i - j - e'- k - h'- l - m - n    feature-branch
    / /
    a - b - c - d - e - f - g - h -------- master
  2. 然后,git reset --soft master。这将使 feature-branch 指向 master,但它会将您的所有更改保留在索引中,随时可以提交。

                i - j - e'- k - h'- l - m - n    (orphaned)
    / /
    a - b - c - d - e - f - g - h -------- master, feature-branch
    \
    (index)
  3. git commit

                i - j - e'- k - h'- l - m - n    (orphaned)
    / /
    a - b - c - d - e - f - g - h -------- master
    \
    n' feature-branch

#2 和#3 的唯一目的是破坏feature-branch 的历史。如果你确定你永远不需要那段历史,那很好。但是,为了删除对实际发生的事情的准确记录而花费所有这些额外的麻烦似乎是一种浪费。

关于git - 我如何使用 Git 作为一次提交 rebase ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30197694/

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