简体   繁体   English

通过更新父分支从子分支 PR 中删除更改

[英]Remove changes from Child Branch PR by updating Parent branch

I've a situation like , I've created a branch B from a Branch A , changed few things and raise a Pull Request .我有这样的情况,我从一个分支 A 创建了一个分支 B,改变了一些东西并提出了一个拉取请求。 Later come to know that those changes should be the part of Branch A and not Branch B , and should not come in PR of Branch B , So if i update the parent branch Branch A( add those changes there), and pull the changes to Branch B , so now does the PR of branch B will show those changes that i added earlier or those will be gone后来知道这些更改应该是分支 A 而不是分支 B 的一部分,并且不应该出现在分支 B 的 PR 中,所以如果我更新父分支分支 A(在那里添加这些更改),并将更改拉到分支 B ,所以现在分支 B 的 PR 会显示我之前添加的那些更改或那些将消失的更改

You can try fast-forwarding from B to A:您可以尝试从 B 快进到 A:

git checkout A
git merge --ff-only B

which will apply the commits to A as they are in B or fail if there's any conflict.这会将提交应用到 A 中,因为它们在 B 中或如果有任何冲突则失败。

Afterwards you can simply git reset --hard <commit> the B branch if you want to change it, or re-create B branch from A once again, so it's 1:1.之后你可以简单地git reset --hard <commit> B 分支,如果你想改变它,或者再次从 A 重新创建 B 分支,所以它是 1:1。

Or, you can use cherry picking , apply only the commits you want and then reset the B branch to commit you desire.或者,您可以使用樱桃采摘,仅应用您想要的提交,然后重置 B 分支以提交您想要的。

Regarding the behavior in a pull request, the B branch will still contain the commits, but the git UI (eg Gitea) will probably not show them as the common commits would then match.关于拉取请求中的行为,B 分支仍将包含提交,但 git UI(例如 Gitea)可能不会显示它们,因为常见的提交随后会匹配。

Alternatively rebase the branch and remove the common commits eg with:或者,重新设置分支并删除常见提交,例如:

git checkout B
git rebase A
git push --force  # to update the PR

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

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