Ivan
Ivan

Reputation: 15932

How to repair duplicates in a Git tree

I don't know how, bug I've arrived to a tree like this:

X1--X2--(a lot commits)--X25--X26 (master)
     \                    \
      \                    D1--D2--merge (demo)
       D1'--D2'---------------------/

Where D1=D1' and D2=D2' and the merge is empty. This tree has been pushed to the server, but I'm the only person is working on it.

Not a problem at all, but I'd like to simplify this tree to a more logical one. Something like this:

X1--X2--(a lot commits)--X25--X26 (master)
                          \
                           D1--D2--merge (demo)

It's possible to remove D1' and D2' from my tree?

Upvotes: 0

Views: 59

Answers (1)

John Feminella
John Feminella

Reputation: 311605

Each commit in git points backwards to its parents. Because merge points to the commits you don't want to have anymore, you need to get rid of merge, not just D1' and D2'.

To do that, use git checkout demo; git reset --hard D2. This will move your demo pointer back to D2.

Note that you will be doing a Very Bad Thing if you push this to the server and anyone has made a commit that depends on merge, D1', or D2'. Their local history will still have the orphaned commits!

Upvotes: 2

Related Questions