How to keep your git fork clean from duplicate commits?
I frequently run into a problem with duplicate commits while maintaining forks with git.
Lets say I've forked a repository and committed a fix. I push the changes to my forked repository and can see the changes on github. All well and good so fa开发者_运维知识库r.
The problem lies when the project maintainer merges my fix into their branch and I later update to stay synced with the main project. My fix would appear twice in my history, the orginial and the time it was merged in by the project maintainer.
Is there a solution for this? It'd be nice to finally clean up my tree.
Were those commits cherry-picked, not merged? If you merge the same commits into two branches, then merge one of those into the other, the commits don't show up twice. You'll see exactly what you expect in the history - two merge commits with the given commit as parent, then those two branches eventually merged:
- o - o - o - o - o - o - o
\ \ / /
\ o - o - o /
\ \ /
o - o - o - o - o
This is a really good reason to merge instead of cherry-picking - and to facilitate that merging, it's important to make sure to start your topic branches from a common ancestor of all branches that may want to merge them, so that those features/bugfixes can be merged cleanly, without picking anything else up.
Note from the op : The commits were applied from Github's fork queue which uses cherry-pick behind the scenes. Accepted, thank you.
精彩评论