简体   繁体   中英

Git - hide merge commits from upstream

I'm using the following workflow for project on Github.

  1. Fork the repository
  2. Merge base master to forked master
  3. Create a branch from forked master and implement something
  4. Create a pull request from my branch to base master
  5. After checks and review, maintainer merges my branch to base master .
  6. Goto 2.

The problem is 2. At first I wasn't expierenced with git, so I did this via the pull request in my fork. Now I do git pull upstream && git merge upstream/master , which creates a new merge commit. After some such merges, my PRs looks like this: 一堆合并提交

As you see, there is a bunch of merge commits. It's really ugly, and it may be quite hard to understand what exactly I want to merge. Moreover, this list grows every time I merge base master to my fork.

Is there a way to hide/remove them? At this moment, I can only consider deleting and re-creating fork every time PR is done, but that's not good, because I may work on A, then switch to B, merge B, go back to A etc. git rebase actually doesn't hide them: merged commits are listed in PR with $user authored and $me commited .

To fix your currently "broken" PR, you can squash all your commits into a single commit. You can do this on the command line with git rebase -i , and changing pick to squash on all but the first commit.

GitHub actually implements this for you as well - if you click the dropdown next to the Merge pull request button, there is an option for Squash & merge , which does the same thing.

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