user1146657 user1146657 - 1 year ago 83
Git Question

Removing merged branch commits in git

I was working with git and created an unnecessary situation by accident. This is how my git history looks like:

\ /

I would like to remove the branching. It does not matter how. I am not a git expert and tried many things without success. Ideally I would like to have:


I don't need a lecture on how preserving the history is important. The changes in
are not significant enough to be a branch.

Answer Source

You can use rebase for this. It will essentially reset the branch to a point you specify, then replay commits over the top again the way you tell it to. In this case you'll exclude commit C:

git rebase -i HEAD~5 # 5 is the number of commits back to rebase
# Comment out or delete the line for commit C
# Save/proceed

As you noted, you don't care about preserving the history. This process will change the commit hashes for the commits after C.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download