还原所有分支特定更改,以便分支反映主分支

编程入门 行业动态 更新时间:2024-10-25 07:26:53
本文介绍了还原所有分支特定更改,以便分支反映主分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有可能在不丢失历史记录的情况下恢复对特定分支所做的所有更改?

我很早以前就会分支主设备来隐藏特定功能,成为主人一样,但我需要完整的分支历史。

master - >分支 - > (回复剥离) - > branches = master

分支现在应该反映 master ,尽管我想提交在分支中包含所有需要到达 master 的变更。

我能想到的最简单的方法是复制 master 的来源并在 branches 中删除/粘贴文件,但是我担心这是否会在后来与主合并时产生冲突?

$ b

解决方案

编辑:

Preuk的解决方案对我不起作用(Git 2.2.1) ,但这些命令的工作: pre $ git checkout branch $ git revert -n master..branched $ git commit -m还原为master

首字母:

我建议使用 git format-patch ,然后加上 git am 分支,压缩 git rebase -i 的提交,然后应用th e分支结果分支:

  • branches :

    $ git checkout branches $ git checkout -b tmpbranch

  • 在 master 和分支:

    $ git format-patch - R master..branched --stdout | git am

  • 将提交压缩为一个:

    $ git rebase -i branches $#使用squash命令除第一个 $#之外的所有提交,并设置日志消息以恢复为主为例。

  • 然后合并并删除临时分支 tmpbranch 到分支:

    $ git checkout branches $ git merge tmpbranch $ git branch -d tmpbranch

    Is it possible to revert all changes made to a specific branch without losing history?

    I branched master a long time ago to hide specific features but now this branch has to become the same as master but I need the branch history intact.

    master -> branched -> (revert stripping) -> branched = master

    The branched should now reflect master although I want a commit in branched with all the changes that was needed to get to master.

    The easiest way I can think of is to copy the sources of master and delete/paste files in branched but my worry is if this will generate conflicts when later merging from master?

    解决方案

    Edit:

    The solution from Preuk does not work for me (Git 2.2.1), but those commands work:

    $ git checkout branched $ git revert -n master..branched $ git commit -m "Revert to master"

    Initial post:

    I would suggest to use git format-patch followed by git am on a dedicated branch, squash the commits with git rebase -i, and then apply the result on the branch branched:

  • Create new branch starting from branched:

    $ git checkout branched $ git checkout -b tmpbranch

  • Apply the reversed commits between master and branched:

    $ git format-patch -R master..branched --stdout | git am

  • Squash the commits into a single one:

    $ git rebase -i branched $ # Use the squash command for all commits except the first one $ # and set the log message to "Revert to master" for instance.

  • Then merge and delete the temporary branch tmpbranch onto branched:

    $ git checkout branched $ git merge tmpbranch $ git branch -d tmpbranch

  • 更多推荐

    还原所有分支特定更改,以便分支反映主分支

    本文发布于:2023-11-26 18:39:47,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1634730.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:分支

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!