简体   繁体   English

Git Rebase主冲突

[英]Git Rebase master conflicts

Im having some conflicts on a branch when rebasing master into it. 我在将master重新编入分支时在分支上有一些冲突。

Scenario is: 场景是:

Branch off master, make some changes, commit said changes. 分支关闭主节点,进行一些更改,然后提交表示的更改。 Checkout master, make some changes, commit said changes, checkout branch-1. 结帐主机,进行一些更改,提交所说的更改,结帐分支1。 Try to rebase master - conflict.. 尝试重新设置主服务器-冲突。

Now I have other developers working in a similar fashion. 现在,我还有其他开发人员以类似的方式工作。

Master is kept in sync on all repo's including the webserver, I don't want master's history being changed. 主机在所有回购协议(包括Web服务器)上保持同步,我不希望更改主机的历史记录。

If I solve the rebase conflicts that are conflicting a point in the past, if I checkout master and merge it with the branch - will masters history be changed - or would those conflict resolutions be applied ontop of all the work im merging? 如果我解决了过去与某个点冲突的基准冲突,如果我结帐master并将其与分支合并-是否会更改master历史-还是将这些冲突解决方案应用于所有合并工作中?

Imagine you have the current situation: 想象一下您当前的情况:

- A - B - C - D
   \          ^
    - X - Y   master
          ^
          branch1

Running git checkout branch1; git rebase master 运行git checkout branch1; git rebase master git checkout branch1; git rebase master will move the commits from branch1 so that they are applied on top of the master branch: git checkout branch1; git rebase master会将提交从branch1移出,以便将它们应用于master分支的顶部:

              master
              v
- A - B - C - D
               \      
                - X - Y 
                      ^
                      branch1

This doesn't change master , but it changes branch1 in two ways: 这不会更改master ,但是会以两种方式更改branch1

  1. By changing the parent of commit X from A to D you'll change the ID of commit X , in fact as far as Git is concerned it's now a whole new commit (and since X has a new ID, Y has a new parent, so Y gets a new ID too, and so on if there are more commits on the branch). 通过将提交X的父级从A更改为D您将更改提交X的ID,实际上,就Git而言,它现在是一个全新的提交(并且由于X具有新的ID, Y具有新的父级,因此Y也会获得新的ID,依此类推(如果分支上有更多提交)。
  2. Any conflict resolution you need to do will change the contents of the commits. 您需要执行的任何冲突解决方案都会更改提交的内容。

If you've already pushed branch1 to a remote repository then it's a very bad idea to rebase it; 如果您已经将branch1送到远程存储库,则对它进行基础化是一个非常糟糕的主意; changing history that's already been shared will only lead to problems. 更改已经共享的历史记录只会导致问题。

Assuming you haven't pushed branch1 , you can then merge it into master (with git checkout master; git merge branch1 ), which will result in master being fast-forwarded to commit Y . 假设您尚未推送branch1 ,则可以将其合并到master中 (使用git checkout master; git merge branch1 ),这将导致master快速转发以提交Y This gives you a tidy linear history without having to change master : 这为您提供了整洁的线性历史记录,而无需更改master

- A - B - C - D - X - Y
                      ^
                      branch1 AND master

If you have already pushed branch1 then you should avoid rebase and use a merge instead (using git checkout master; git merge branch1 ), which won't change the history of either of them but will create a new commit (marked M in this diagram) on the master branch: 如果您已经推送了branch1 ,则应避免重新设置基础,而应使用合并(使用git checkout master; git merge branch1 ),这不会更改任何一个的历史记录,但会创建一个新的提交(此图中标记为M )在master分支上:

- A - B - C - D - M
   \            / ^
    - X - Y - -   master
          ^
          branch1

If you rebase, regardless of which branch you rebase into, you are changing the history of your repository. 如果您进行了基准调整,则无论您将基准转换为哪个分支,都将更改存储库的历史记录。 The idea is that when the other developers people pull master (from say origin) after you have pushed, their repos will be up to date as well. 这个想法是,当其他开发人员在您推动之后(从起源)拉出master时,他们的存储库也将是最新的。

To be clear: merge conflicts while rebasing will not change the history of master. 需要明确的是:在重新定基时合并冲突不会更改主数据库的历史记录。 Rebasing as a merge method will. 重新合并为合并方法。

If you want to not change the history of master, you cannot rebase as a merge method. 如果不想更改主服务器的历史记录,则不能将其作为合并方法进行重新设置。 The default git merging behavior should work just fine for you, conflicts or not. 默认的git合并行为应该对您来说很好,无论是否冲突。

git checkout master
git merge branch-1

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM