【问题标题】:Remove merge without losing local commit删除合并而不丢失本地提交
【发布时间】:2020-07-20 20:11:09
【问题描述】:

我有两个分支,分别称为“task1”和“task2”。现在我在“task1”分支工作。

我做了一个git merge task2,它工作正常。现在我想在“task1”中编写一些代码,然后我想删除该合并而不丢失我刚刚所做的更改。

我该怎么做?

【问题讨论】:

    标签: git git-branch git-merge


    【解决方案1】:

    所以,您想保留当前分支 task1 的 content,但在其起点(即您解释的起点)之后仅显示 1 个修订版?如果是这样的话:

    git checkout task1
    git reset --soft HEAD~2
    git commit -m "Merge and the last commit joined together, no merge will show up"
    

    你就完成了。

    【讨论】:

    • 抱歉,我想我的问题问错了。我会更新的。
    【解决方案2】:

    您可以使用git revert 撤消合并提交引入的所有更改。

    git log ## to get commit hash from merge
    git revert <merge-commit-hash>
    

    了解更多关于 git revert here 的详细信息。

    【讨论】:

      【解决方案3】:

      切换到分支task1

      git checkout task1
      

      merge task2task1 中。这将生成一个将 HEAD 指定给特定提交的提交

      git merge task2
      

      task1 进行一些更改并提交更改

      ...
      

      合并分支之前找到提交哈希

      git log
      

      reset task1merging task1 到 task2 之前。使用--soft,文件更改将保留在您的工作树中。

      git reset --soft <commit_before_merge>
      

      Tutorial for undo a merge

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-06-11
        • 1970-01-01
        • 2012-11-08
        • 2018-12-08
        • 2010-09-30
        • 2021-12-09
        • 2021-02-15
        相关资源
        最近更新 更多