简体   繁体   中英

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 commit
  4. git push origin feature/db/projectImport (staying in that branch)

Now in GitHub:
5. Click the Compare & pull request button and finally merge with the default merge button, which claim to use --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. Is this possible???

Related Images from the repo

Feature branch commits: 功能分支提交

Dev branch commits: dev 分支提交

Note:

  • I am newbie in 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.

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. 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.

Now, that's a bit of a funny workflow to me: when I merge a PR in, I systematically delete the feature branch. But your workflow should work fine too.

How to do it

On GitHub

Once you have your PR ready to merge, make sure you merge it in using GitHub's "squash and merge" method:

压缩和合并 PR

On the 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 .

Once you've completed the merge, dev will have one new commit, and branch feature/feature-name will remain unmodified.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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