且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Git:如何在没有重复的PR合并提交的情况下同步我的本地和上游存储库?

更新时间:2022-10-25 14:29:47

如果我对您的理解正确,那么您的状态或多或少是这样的:

(黑色=上游,蓝色=功能,绿色=主)

因此,当您将上游合并到master中时,您会得到:

您需要一个本地集成分支和一个上游同步分支. 您可以使用本地集成分支来合并功能(现在在master中正在执行的操作). 然后,您可以使用upstream跟踪上游合并.

进行PR并在上游被接受时,您会在upstream分支中将其作为合并接收,而本地集成分支(在这种情况下为master)不会与合并 feature分支

此后,您可以在master中安全地合并upstream,并且在master中获得一个合并.或者,如果您确实不想进行任何合并,则可以使用重新设置.. >

I need to merge my own pull request feature branch onto my local repo's master branch. However, if the upstream maintainer merges my pull request, I'll have to pull in another merge commit. Git doesn't realize that I already merged the same branch before, so instead I have 2 merge commits for the same branch.

How do you guys sync your local and upstream repositories without duplicate merge commits?

If I understand you correctly, your status is more or less this:

(Black = upstream, blue = feature, green = master)

So, when you merge upstream into master, you get this:

You need a local integration branch and an upstream-synced branch. You use the local integration branch to merge your features (what you are doing in master right now). And you use the upstream to keep track of upstream merges.

When you make a PR and it's accepted upstream, you receive it as a merge in your upstream branch, while you local integration branch (master in this case) is not merged with the feature branch

After that you can merge upstream safely in master, and you get one merge in master. Or if you really don't want any merges, you can use rebase.