简体   繁体   English

合并拉取请求后,如何防止来自功能分支的提交出现在开发分支中?

[英]How to prevent commits from a feature branch from showing up in the dev branch after the pull request is merged?

What I have done我做了什么

In local repo:在本地仓库中:

  1. git checkout -b feature/db/projectImport dev
  2. make changes做出改变
  3. git add. and git commitgit commit
  4. 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



Pull request Image拉取请求图像拉取请求


What I want to achieve我想要达到的目标

  • I don't want the commits messages from the feature branch to appear in the commit messages in the dev branch.我不希望功能分支的提交消息出现在开发分支的提交消息中。
  • When I merge the 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???这可能吗???

Related Images from the repo来自回购的相关图片

Feature branch commits:功能分支提交: 功能分支提交

Dev branch commits:开发分支提交: dev 分支提交

Note:笔记:

  • I am newbie in git .我是git的新手。 So, my thinking can be wrong.所以,我的想法可能是错误的。 If this is the case, please point out my mistake and tell what is correct.如果是这种情况,请指出我的错误并告诉我什么是正确的。
  • Any suggestion gratefully received.任何建议都非常感激。 Thanks in advance.提前致谢。

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.但是您的工作流程也应该可以正常工作。

How to do it怎么做

On GitHub在 GitHub

Once you have your PR ready to merge, make sure you merge it in using GitHub's "squash and merge" method:准备好 PR 合并后,请确保使用 GitHub 的“压缩和合并”方法将其合并:

压缩和合并 PR

On the Git CLI在 Git CLI 上

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

The results结果

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.

相关问题 如何从功能分支的拉取请求中删除以前的合并和提交? - How to remove previous merges and commits from the pull request on a feature branch? 从 dev 到 master 分支的拉取请求不显示差异但提交 - Pull request from dev to master branch doesnt show diff but commits 从dev分支中删除后如何获取master分支的提交 - How to get the commits for master branch after dev branch is cut from it 在 github 的“合并拉取请求”操作之后,所有来自功能分支的提交和一个新的合并提交出现在开发分支上 - After github "merge pull request " action, all commits from the feature branch and a new merge commit appearing on the develop branch 从master的dev和feature分支中提取 - taking pull from dev and feature branch in master 如何从拉取请求的功能分支中删除特定于操作系统的提交? - How to remove OS-specific commits from feature branch for pull request? 从主分支恢复合并的拉取请求 - Revert a merged pull request from master branch 如何从合并分支移动提交? - How to move commits from merged branch? 如何使用合并的分支从 TFS 拉取请求中对 Jenkins 作业进行排队 - How to queue Jenkins job from TFS pull request with merged branch 从GitHub Pull Request中的不同分支提交 - Commits from different branch on GitHub Pull Request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM