git Bitbucket:远程仓库中的冲突,不知道如何解决

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21003971/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:33:17  来源:igfitidea点击:

Bitbucket: Conflict in remote repo, can't figure out how to resolve

gitbitbucketgit-mergemerge-conflict-resolution

提问by Siraris

I hope I can express this properly... I have the following setup in Bitbucket (using Git protocol). I have a master repo that contains my application. I then fork the master repo per client in order to have the flexibility to make client specific changes without affecting the master. When a generic change is required, I push to master, and then sync with the fork and then do a pull into production.

我希望我能正确表达这一点......我在 Bitbucket 中有以下设置(使用 Git 协议)。我有一个包含我的应用程序的主存储库。然后我分叉每个客户端的主存储库,以便在不影响主库的情况下灵活地进行客户端特定的更改。当需要进行通用更改时,我会推送到 master,然后与 fork 同步,然后拉入生产。

The issue I'm having is that in Bitbucket, it's saying I have merge conflicts, but I have no clue how to resolve them. Locally, I have no conflicts. When I go into Bitbucket, it tells me I'm 2 commits behind the master repo so I click sync. It says there's merge conflicts, and I need to resolve them. I then see no way to resolve these conflicts. If I do a pull on the production server, it says there's conflicts and I need to resolve them, so I do. I go in with nano (as I HATE VIM) and clean out what I need to, and go about my business. But yet the forked repo seems to still be in conflict. I have no clue what I need to do in order to resolve this situation. Regardless, it has me at a standstill because I can't push any more changes to the fork until the conflicts get resolved.

我遇到的问题是在 Bitbucket 中,它说我有合并冲突,但我不知道如何解决它们。在本地,我没有冲突。当我进入 Bitbucket 时,它告诉我我在主存储库后面有 2 个提交,所以我单击同步。它说存在合并冲突,我需要解决它们。然后我看不到解决这些冲突的方法。如果我拉动生产服务器,它会说存在冲突,我需要解决它们,所以我这样做了。我使用 nano(因为我讨厌 VIM)并清理我需要的东西,然后开始我的工作。但是分叉的回购似乎仍然存在冲突。我不知道我需要做什么才能解决这种情况。无论如何,它让我处于停滞状态,因为在冲突得到解决之前我无法对分叉进行任何更改。

回答by Chris

When working with a fork, it is often helpful to have the upstream repository (your Master repository) configured as a remote as well as the fork (your Client A repository). For example, you probably already have an originthat represents the fork.

使用 fork 时,将上游存储库(您的主存储库)配置为远程和 fork(您的客户端 A 存储库)通常很有帮助。例如,您可能已经有一个origin代表分叉的。

Add a new remote upstreamto represent the "Master" repository:

添加一个新的遥控器upstream来代表“主”存储库:

git remote add upstream [email protected]:user/master-repo.git
git fetch upstream

Now you should be able to see all of the relevant branches. For instance, if you're trying to merge the masterbranch, these will be relevant:

现在您应该能够看到所有相关的分支。例如,如果您尝试合并master分支,这些将是相关的:

  • master(local)
  • origin/master(Client A)
  • upstream/master(Master repo)
  • master(当地的)
  • origin/master(客户A)
  • upstream/master(主回购)

If you visualize these branches with gitkor git log --all --graph --decorateyou will probably be able to see where the conflict is coming from. Most likely you will want to merge changes from both remotes into your local masterbranch:

如果您使用gitk或可视化这些分支,git log --all --graph --decorate您可能会看到冲突的来源。您很可能希望将来自两个遥控器的更改合并到您的本地master分支中:

git checkout master
git merge upstream/master  # (Merge changes from the "Master" repo)
# Fix any merge conflicts that may arise
git merge origin/master    # (Merge changes from the Client A repo)
# Fix any merge conflicts that may arise

Once you have done this, you should be able to pushcleanly to origin:

完成此操作后,您应该能够push干净利落地origin

git push origin master