[英]How to prevent commits from a feature branch from showing up in the dev branch after the pull request is merged?
In local repo:在本地仓库中:
git checkout -b feature/db/projectImport dev
git add.
and git commit
git commit
git push origin feature/db/projectImport
(staying in that branch) git push origin feature/db/projectImport
(留在那个分支) Now in GitHub:现在在 GitHub 中:
5. Click the Compare & pull request button and finally merge with the default merge button, which claim to use --no-ff
5.点击Compare & pull request按钮,最后与默认的merge按钮合并,该按钮声称使用
--no-ff
feature
branch into dev
, the feature branch will retain all its commits but the dev
branch will only have the merge commit.feature
分支合并到dev
时,功能分支将保留其所有提交,但dev
分支将只有合并提交。 Is this possible???Feature branch commits:功能分支提交:
Dev branch commits:开发分支提交:
Note:笔记:
git
.git
的新手。 So, my thinking can be wrong. As others have pointed out in the comments, what you are looking for is the squash option when you merge the PR in.正如其他人在评论中指出的那样,当您合并 PR 时,您正在寻找的是 squash 选项。
When you squash-merge, that changes what appears on the destination branch, but it does not change what is on the source branch.当您压缩合并时,这会更改目标分支上显示的内容,但不会更改源分支上的内容。 So on dev, you'll see one commit.
所以在 dev 上,你会看到一个提交。 But on the feature branch, as long as you don't delete it, you'll continue to see all your original feature commits.
但是在功能分支上,只要不删除它,您将继续看到所有原始功能提交。 And the PR will continue to hold a pointer to that branch.
PR 将继续持有指向该分支的指针。
Now, that's a bit of a funny workflow to me: when I merge a PR in, I systematically delete the feature branch.现在,这对我来说有点有趣:当我合并 PR 时,我会系统地删除功能分支。 But your workflow should work fine too.
但是您的工作流程也应该可以正常工作。
Once you have your PR ready to merge, make sure you merge it in using GitHub's "squash and merge" method:准备好 PR 合并后,请确保使用 GitHub 的“压缩和合并”方法将其合并:
If you're doing the merge on your own computer, the same operation can be accomplished like this:如果您在自己的计算机上进行合并,则可以像这样完成相同的操作:
git checkout dev
git merge --squash feature/feature-name
git push origin dev
With either method, you will get to write a new message for the squashed commit that will get added to dev
.无论使用哪种方法,您都可以为将添加到
dev
的压缩提交编写新消息。
Once you've completed the merge, dev
will have one new commit, and branch feature/feature-name
will remain unmodified.完成合并后,
dev
将有一个新的提交,并且分支feature/feature-name
将保持不变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.