简体   繁体   中英

How to merge a pull request without getting a merge commit in the Git history

On Github every time I merge a pull request into my base branch I get an extra merge commit:

Merge pull request #77 ...

I prefer to get a git history without these merge commits.

How can I achieve that?

To get a git history without any pull request merge commits I can use the merge button (Pull request page) and perform a rebase and merge:

在此输入图像描述

I will never understand (or, I should say, agree with) all the people who insist that merges in the history are "less clean". But ok, here are your options:

  • Squash
  • Rebase
  • Merge

A squash will result in a single new commit representing all changes at the head of the main branch. It is a special case of rebase.

A rebase will result in one or more new commits (any or all of which may be in a "broken"/unbuildable state - but hey, this is your definition of clean, not mine) at the head of the main branch.

A merge creates a merge commit and leaves history as it really happened.

Here is documentation of the options: https://github.com/blog/2243-rebase-and-merge-pull-requests

(Yes, I'm aware of the standard gripe that external links aren't reliable. If github's site goes away, then the question becomes moot anyway; so I'm not retyping their documentation.)

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