还原所有分支特定更改,以便分支反映主分支 [英] Revert all branch specific changes so the branch reflect master

查看:102
本文介绍了还原所有分支特定更改,以便分支反映主分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

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分支结果分支


  1. branches

      $ git checkout branches 
    $ git checkout -b tmpbranch


  2. master 分支

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


  3. 将提交压缩为一个:

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

  4. 然后合并并删除临时分支 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:

  1. Create new branch starting from branched:

    $ git checkout branched
    $ git checkout -b tmpbranch
    

  2. Apply the reversed commits between master and branched:

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

  3. 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.
    

  4. Then merge and delete the temporary branch tmpbranch onto branched:

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

这篇关于还原所有分支特定更改,以便分支反映主分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆