Git undo pushed merge and delete its history

前端 未结 2 1181
一个人的身影
一个人的身影 2021-01-28 08:52

I made an accidental merge to master and pushed it, now master has all the commits from dev. I want to revert the commits from master and delete its history without changing dev

2条回答
  •  迷失自我
    2021-01-28 09:16

    You could use the reflog to find out where was master pointing to before the merge, and use the reset command to reset it to that. The commits won't be deleted because there're still in dev, but master won't have them. If you really want to delete those, i.e., also reset dev, you may do, and the orphan commits will eventually be garbage-collected.

    Here's an example, but don't just use it as a recipe, rather, read some more about Git and how Git works (git structures) and practice elsewhere (other branches / other repos), and when you're confident come back to this one and try.

    Recovering lost commits

提交回复
热议问题