繁体   English   中英

Github:提交拉取请求后将 `master` 分支合并到 `feature` 分支

[英]Github: Merge `master` branch into `feature` branch after submiting pull request

我不确定它是否可行。 我已经尝试过一些像变基/合并这样的事情,但无论我尝试过什么,总是会进入 PR diff。

这就是我所拥有的和我想要的,

我有一个主(默认)分支,然后我创建了一个功能分支来进行更改并针对它提出了 PR。

现在更多更改已合并到 Master 中,我需要使用这些更改来修复评论意见(主要是一些实用程序用法和库)。 所以,基本上我尝试分别对两者进行变基/合并以查看它是如何进行的,并且我总是以额外的提交作为我的 PR diff 的更改而不仅仅是我的更改。

github有什么办法可以实现吗? 不仅仅是创建一个新的功能分支并创建新的 PR 并放弃旧的。

编辑:

这是我试过的,

1. Using Rebase
> git checkout master
> git checkout -b feature
> // make changes & commit on feature
> git push origin feature
> git checkout master
> // made some changes & commit on master
> git push origin master

// now rebase
> git checkout feature
> git rebase master
> git push origin feature // fails as it complains HEAD being different from remote feature branch due to earlier rebase
> git pull --rebase
> git push origin feature


This set-up is adding master changes in the PR as diff and commit-id is changed in feature branch as well (expected due to rebase).

而除了 rebase 之外的相同步骤集,如果我合并,它不会显示在 PR diff 中。

最后,在浏览了更多帖子之后,这里是有效的,但不会导致 PR 中弹出窗口的主更改(w/rebase 选项)

> git checkout master
> git checkout feature
> //make change & commit
> git push origin feature
> git checkout master
// make change & commit
> git push origin master
> git checkout feature
> git rebase origin/master // you can do just master to rebase against local
> git push -f origin feature // this is important otherwise you will see error and it will ask to do `git pull --rebase origin feature` which will cause master changes to appear in the diff. I feel like github has issues...and it's should do diff based on content rather than commits. but any ways

发生这种情况的原因是因为您将feature分支的新(正确)版本重新定位在它的旧(过时)版本之上。 这不仅重写了您的提交,还重写了您从master获得的新提交,这些新提交还没有出现在您的feature分支的旧副本上。

您已经从评论和更新的问题中发现的解决方案可以概括为:

当你使用 rebase 工作流时,你需要在之后强制推送你的个人功能分支。

(旁注:您应该很少(如果有的话)强制推送共享分支,例如master 。)

您使用的一系列命令使您能够跳过强制推送:

git pull --rebase
git push origin feature

意味着您将所有提交(也包括master上的新提交)重新定位(重播)到分支的旧版本,然后将其推出。

请注意,一般来说,我很少支持显式获取。 因此,要使用最新的master更新您的feature分支,您可以根据需要经常执行此操作(但可能每天至少一次):

git fetch
git rebase origin/master feature

# If you want to update a PR, or even just backup your commits in case your machine dies
git push --force-with-lease

请注意,即使您当前没有检出feature ,上面的 rebase 命令也可以使用。 如果您已经签出它,则可以省略分支名称的最后一个参数。

这不只是基于(远程)开发吗? 你完全可以在打开 PR 的同时做到这一点。 为此,请检查您的功能分支

git checkout branch

然后获取远程代码中的新更改

git fetch upstream

并实施它们

git rebase upstream/master

或者

git rebase upstream/develop

取决于合并远程仓库中更改的位置。

顺便说一句,许多人更喜欢将远程更改合并到他们自己的masterdevelop中,然后将他们的feature rebase 到他们自己的本地develop中。 这是因为许多开发人员更喜欢拥有一个本地干净的副本来使事情井井有条。

如果我遗漏了什么,请告诉我。

暂无
暂无

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

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