git: remove duplicate commits from public branch?
I've somehow got some duplicate commits in a branch, each with the same chan开发者_运维技巧ges. It's a public branch, merged from several branches by several users. I need to periodically rebase this branch onto the master branch of another repo, and these duplicates make it clumsy.
Is there a way to remove these and push them to the public repo w/out making it complicated for other users working from the branch?
filter-branch is not necessary in this case IMHO and as Jefromi mentioned without making life a bit complicated for everybody else it is impossible. First rule of Git - do not rewrite published history.
If you really want to cleanup the branch that has got messed up, then you should rebase it locally, rearrange commits and force-push it to mainline if needed.
in order to do that (imagine that the branch is checked out locally and the last known good state after which you have started to get those duplicates is 20 commits ago)
git checkout yourPublicBranch
git rebase -i HEAD~20
This will fire up the editor in which you will be able to manage the commits. Then you will have to save the file and exit for rebase to start working. That may lead to conflicts.
Use git filter-branch to rewrite the history. Here's a good intro from github:
http://help.github.com/removing-sensitive-data/
精彩评论