是否有可能在不丢失历史记录的情况下恢复对特定分支所做的所有更改?
我很早以前就会分支主设备来隐藏特定功能,成为主人一样,但我需要完整的分支历史。
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命令除第一个 $#之外的所有提交,并设置日志消息以恢复为主为例。
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 tmpbranchApply the reversed commits between master and branched:
$ git format-patch -R master..branched --stdout | git amSquash 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
更多推荐
还原所有分支特定更改,以便分支反映主分支
发布评论