【问题标题】:feature branch got master commits after merge合并后功能分支 git master 提交
【发布时间】:2019-08-29 14:03:26
【问题描述】:

所以我有一个master 分支和feature/123-branch

我在 feature/123-branchgit checkout feature/123-branch 上发现它已经过时了 master 所以我这样做了

git merge master 保持最新状态。

merge 之前,feature/123-branch 只是 2 commits 我为开发该功能所做的,但当我这样做时

git push origin feature/123-branch

由于合并,提交数量跃升至 40(我认为?)。

我尝试了rebase --onto master HEAD~1 feature/123-branch,但它没有解决问题。

我怎样才能让2 commits 上的2 commits 保持最新状态?

【问题讨论】:

    标签: git github git-merge


    【解决方案1】:

    如果我理解正确,你有这样的事情:

    M0-M1-M2-M3-M4-...-MX  (master)
         \
          F0-F1            (feature branch)
    

    你想通过这样来“保持最新”:

    M0-M1-M2-M3-M4-...-MX         (master)
                        \
                         F0'-F1'  (feature branch)
    

    提交 F0'F1' 是提交 F0F1(来自您的功能分支的提交),但略有更改,以便在 master 的最后一次提交之后发生更改

    如果这是您想要做的,那么您想要做的不是合并 master 和您的功能分支,而是将您的功能分支重新基于 master。

    在这种情况下,方法如下:

    1. git checkout feature/123-branch 确保您在功能分支中
    2. git log 列出该分支上的最新提交,并找到 F1 对应的哈希
    3. git reset --hard the_hash_from_F1 回滚合并
    4. git rebase master 做你最初打算做的事情并“更新”你的分支

    【讨论】:

    • 我在写的过程中差不多,你打败了我。 (+1)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    • 2021-03-22
    • 1970-01-01
    • 2018-04-03
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    相关资源
    最近更新 更多