简体   繁体   English

尝试合并两个分支(一个分支很旧,尝试提取主代码),但是每个文件中都有冲突

[英]Trying to merge two branches (one is very old, trying to pull master code) but there are conflicts in every file

the conflicts shouldn't even be conflicts... most of them are on the documentation I added, like tihs: 冲突甚至不应该是冲突...大多数冲突都在我添加的文档中,例如tihs:

<<<<<<< HEAD
  # returns the max_sequence for this section
=======
>>>>>>> merged with other_branch_that_isnt_master

the command I did was git pull --rebase origin master 我做的命令是git pull --rebase origin master

but when I just do git pull origin master , I still get tons of conflicts everywhere. 但是当我只是做git pull origin master ,到处仍然有很多冲突。

Why is it not merging appropriately? 为什么没有适当地合并? it's like git gave up on life. 就像git放弃了生命。

How do I get git to actually merge my files? 如何获得git实际合并我的文件?

I'm using git on Mac Lion. 我在Mac Lion上使用git。

It is likely that you committed to the wrong branch and had the branches diverge. 您可能选择了错误的分支并导致分支分歧。 This means that a rebase will no longer cleanly apply, creating conflicts. 这意味着重新基准将不再完全适用,从而产生冲突。

One option is to perform a git merge and do the hard manual work of fixing the conflicts. 一种选择是执行git merge并完成解决冲突的艰苦的手动工作。 Once the branches have merged, you should only need to do the work once. 分支合并后,您只需要做一次工作。

Another option is to ignore all of the changes in the other copy of master and make your copy the authoritative one. 另一种选择是忽略master另一个副本中的所有更改,并使您的副本具有权威性。 This is not recommended, but it depends on your use case: 不建议这样做,但这取决于您的用例:

git fetch
git merge -s ours origin/master

Another option is to rewrite and fix the commit history as Dave has suggested. 另一种选择是按照Dave的建议重写并修复提交历史记录。 A summary follows: 总结如下:

  • Use gitk --all or git log --graph --all to visualise the history and see where the branches have diverged. 使用gitk --allgit log --graph --all可视化历史记录,并查看分支的分支位置。
  • Use git reset --hard to rewind history to that commit 使用git reset --hard将历史回滚到该提交
  • Do a git pull --rebase 做一个git pull --rebase
  • git cherry-pick your commits back onto the rebased history, hopefully minimising conflicts. git cherry-pick 您的提交回到重新建立的历史上,希望将冲突降到最低。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 合并两个分支不是主人 - Merge two branches not master git:试图合并分支,但是有大量的冲突,其中大多数/不应该/是冲突 - git: trying to merge branches, but there are TONS of conflicts, and most of them /shouldn't/ be conflicts 将两个git存储库合并为一个,保留(重命名)主分支 - Merge two git repositories into one, keeping (renamed) master branches 分别合并到qc和master时合并分支之间的冲突 - Merge conflicts between branches when merging to qc and master separately 如何同步两个存储库(在github中一个和gitlab中)的所有分支,以防止合并冲突? - How to sync all branches of two repositories (one in github and one in gitlab) preventing merge conflicts? 将文件移动到主文件夹中。 现在分支有合并冲突 - Moved files into folders in master. Now branches have merge conflicts 预测功能分支在主分支中合并时的合并冲突 - Predicting merge conflicts between feature branches when they are merged in the master branch 尝试合并时查看文件的历史记录,显示两个分支 - View the history of a file while trying to merge, showing both branches 试图从 git 中删除身份验证会创建奇怪的合并冲突和不应该存在的更改 - Trying to remove authentication from git pull creating strange merge conflicts and changes that shouldn't exist 如何在两个分支中合并拉取请求? - how to merge a pull request in two branches?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM