Git 合并错误
Git wrong merging
我说明问题
这是我的实际 git
我在合并时遇到问题,在与蓝色分支 4 合并期间,红色分支中还原的文件被忽略。
基本上,我们开始在 red branch 上开发一个功能,然后决定更改分支,为了使 red branch "pure" 没有错误,我们恢复了该功能的初始更改。
我们继续在蓝色分支上开发该功能,这是基于我们已经在红色分支上所做的工作。
有很多文件renaming/deletion,并且有变化。
现在,我合并蓝色和红色时,一半的变化没有保留,甚至没有冲突。
我用我们想要的东西制作了另一个分支(让我们称它为紫色),我想知道有一种方法可以将紫色分支推入红色分支,以准确保留其中的内容紫色分支
修复 red
分支(历史不会改变): 一种方法是还原 revert-commit-1
& revert-commit-2
然后合并 blue
分支到 red
分支。
$ git checkout red # checkout to 'red' branch
$ git log # copy the 'revert-commit-2' & 'revert-commit-1' commit hash
$ git revert <revert-commit-2-hash>
$ git revert <revert-commit-1-hash>
$ git pull origin blue # merge the blue branch changes
另一种方式:用purple
分支替换当前red
分支(red
分支历史将被更改)
# first backup the 'red' branch for just safety
$ git checkout red
$ git branch red.bac
# replace red branch with purple branch
$ git checkout purple
$ git branch -D red # delete 'red' branch
$ git checkout -b red # create & checkout to new local 'red' branch with 'purple' branch history
# now if you pushed the 'red' branch already then you need to do force (-f) push otherwise do normal push
$ git push -f origin red
我说明问题
这是我的实际 git
我在合并时遇到问题,在与蓝色分支 4 合并期间,红色分支中还原的文件被忽略。
基本上,我们开始在 red branch 上开发一个功能,然后决定更改分支,为了使 red branch "pure" 没有错误,我们恢复了该功能的初始更改。
我们继续在蓝色分支上开发该功能,这是基于我们已经在红色分支上所做的工作。
有很多文件renaming/deletion,并且有变化。
现在,我合并蓝色和红色时,一半的变化没有保留,甚至没有冲突。
我用我们想要的东西制作了另一个分支(让我们称它为紫色),我想知道有一种方法可以将紫色分支推入红色分支,以准确保留其中的内容紫色分支
修复 red
分支(历史不会改变): 一种方法是还原 revert-commit-1
& revert-commit-2
然后合并 blue
分支到 red
分支。
$ git checkout red # checkout to 'red' branch
$ git log # copy the 'revert-commit-2' & 'revert-commit-1' commit hash
$ git revert <revert-commit-2-hash>
$ git revert <revert-commit-1-hash>
$ git pull origin blue # merge the blue branch changes
另一种方式:用purple
分支替换当前red
分支(red
分支历史将被更改)
# first backup the 'red' branch for just safety
$ git checkout red
$ git branch red.bac
# replace red branch with purple branch
$ git checkout purple
$ git branch -D red # delete 'red' branch
$ git checkout -b red # create & checkout to new local 'red' branch with 'purple' branch history
# now if you pushed the 'red' branch already then you need to do force (-f) push otherwise do normal push
$ git push -f origin red