开发者

git: remove duplicate commits from public branch?

开发者 https://www.devze.com 2023-03-01 08:45 出处:网络
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 thi

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消