martin's
martin's

Reputation: 3955

How to cleanup git history?

I have this:

* [f037cb3] (HEAD, master, branch-01) More cleanup
* [9d3d167] Trying to cleanup
| *   [e524891] (refs/stash) On (no branch): Checkout 75d5bbe7e935eef26b88af304838c04abb60c629 at 7/5/14 12:31 A| |\
|/ /
| * [cf4235c] index on (no branch): 22c8c38 Before implementing blueprints
|/
* [22c8c38] Before implementing blueprints
* [3cff07c] Switched to Bootstrap
* [a4d5973] Added basic unit test
* [a14a6ab] Added 404 and 500 error pages
* [869bf35] Added user_id to stored session data
* [08dcf3b] Updated forms
* [9fc43b7] Added user registration
* [2e41a3c] Added database file to git
* [4eccb17] Renamed database file
* [e9820fc] Added user registration
* [02a2448] Most of the transition to SQLAlchemy is done. Commit just before adding forms.py
* [dcc0f56] Before switching to Flask-SQLAlchemy

How do I get rid of these two?

[e524891] (refs/stash) On (no branch): Checkout 

[cf4235c] index on (no branch): 22c8c38 Before implementing blueprints

Upvotes: 2

Views: 187

Answers (1)

VonC
VonC

Reputation: 1328282

If those commits are not references by any branch, one simple trick is to clone your repo.

The new clone should get a clean history: master commits only.

As zerkms comments, you can run git gc, but I prefer keeping the first repo as it is (in case I need to find some lost data back), and work with a new clone.

By having to run a git gc --prune=now, you might drop more than you intended.

You see other cleaning techniques in "How to remove unreferenced blobs from my git repo".

Upvotes: 1

Related Questions