Chris G.
Chris G.

Reputation: 25984

git - how to make a clean repository

Setting up a git repository with some messy commits. Everything is working and all good, but I would like to remove/delete the messy commits - how do you go about doing that?

Thanks

Upvotes: 0

Views: 1315

Answers (2)

Andy
Andy

Reputation: 46494

If you want to go through the entire history, I think the best way would be an interactive rebase

git checkout master
git tag oldmaster
git branch newbranch sha1ofRootCommit
git rebase -i newbranch

Your editor should pop up. Delete the lines of the commits you don't want. If everything goes well and there were no conflicts, master should contain your clean history.

Here is a link to a similar question

As CharlesB said you can squash commits into a single one if you still want to keep the changes by replacing pick with squash instead of deleting the line.

Upvotes: 4

Kit Ho
Kit Ho

Reputation: 26998

Your TREE

A--B--C--D--E--HEAD

If you want to reset to commit C, say the final outcome

A--B--C--HEAD, you can do

git reset --hard <shasum of your commit C>

If you want to remove commit C only,

A--B--D--E--HEAD, you can do

git rebase --onto <shasum of B> <shasum of C>

Hope it helps

Upvotes: 1

Related Questions