在Git仓库中更新针对master的过时分支

时间:2022-06-06 02:57:53

I have a Git repository that has branch (local and remote) that has become outdated. I would like to bring this branch up to date with the master branch, but I don't know how to do this. There will also probably be many merge conflicts.

我有一个Git存储库,它具有已经过时的分支(本地和远程)。我想把这个分支与主分支联系起来,但我不知道该怎么做。也可能存在许多合并冲突。

How can I bring or update this out-of-date branch to the same state as the master branch?

如何将这个过时的分支带到或更新到与主分支相同的状态?

1 个解决方案

#1


134  

Update the master branch, which you need to do regardless.

更新主分支,无论如何都需要执行此操作。

Then, one of:

然后,其中一个:

  1. Rebase the old branch against the master branch. Solve the merge conflicts during rebase, and the result will be an up-to-date branch that merges cleanly against master.

    将旧分支重新对准主分支。在rebase期间解决合并冲突,结果将是一个与master完全合并的最新分支。

  2. Merge your branch into master, and resolve the merge conflicts.

    将您的分支合并为master,并解决合并冲突。

  3. Merge master into your branch, and resolve the merge conflicts. Then, merging from your branch into master should be clean.

    将master合并到您的分支中,并解决合并冲突。然后,从你的分支到主人的合并应该是干净的。

None of these is better than the other, they just have different trade-off patterns.

这些都不比另一个好,它们只是有不同的权衡模式。

I would use the rebase approach, which gives cleaner overall results to later readers, in my opinion, but that is nothing aside from personal taste.

我会使用rebase方法,在我看来,这给后来的读者带来了更清晰的整体效果,但除了个人品味之外没什么。

To rebase and keep the branch you would:

要改变并保留分支,你会:

git checkout <branch> && git rebase <target>

In your case, check out the old branch, then

在你的情况下,检查旧分支,然后

git rebase master 

to get it rebuilt against master.

让它重建对主人。

#1


134  

Update the master branch, which you need to do regardless.

更新主分支,无论如何都需要执行此操作。

Then, one of:

然后,其中一个:

  1. Rebase the old branch against the master branch. Solve the merge conflicts during rebase, and the result will be an up-to-date branch that merges cleanly against master.

    将旧分支重新对准主分支。在rebase期间解决合并冲突,结果将是一个与master完全合并的最新分支。

  2. Merge your branch into master, and resolve the merge conflicts.

    将您的分支合并为master,并解决合并冲突。

  3. Merge master into your branch, and resolve the merge conflicts. Then, merging from your branch into master should be clean.

    将master合并到您的分支中,并解决合并冲突。然后,从你的分支到主人的合并应该是干净的。

None of these is better than the other, they just have different trade-off patterns.

这些都不比另一个好,它们只是有不同的权衡模式。

I would use the rebase approach, which gives cleaner overall results to later readers, in my opinion, but that is nothing aside from personal taste.

我会使用rebase方法,在我看来,这给后来的读者带来了更清晰的整体效果,但除了个人品味之外没什么。

To rebase and keep the branch you would:

要改变并保留分支,你会:

git checkout <branch> && git rebase <target>

In your case, check out the old branch, then

在你的情况下,检查旧分支,然后

git rebase master 

to get it rebuilt against master.

让它重建对主人。