12

I really dislike to have monster .git folder (2GB) and I don't care about changes in 2002 and I don't want to create new repository so what should I do to clean .git / log ?

Note that I want it not local-only, next time I want to clone repository without history or with history since 2011 year.

thank you

cnd
  • 29,085
  • 60
  • 169
  • 294
  • 1
    Have a look at [this answer](http://stackoverflow.com/a/8483112/357743). I don't know how much it'll reduce `.git` directory size, but it's the most simple way to try that won't make any breaking changes to your repository history. Answers to [this question](http://stackoverflow.com/questions/4515580/how-do-i-remove-the-old-history-from-a-git-repository) might be useful as well. – KL-7 Jan 23 '12 at 09:55

3 Answers3

7

From your question, I think you want something like this.

git-rebase(1) does exactly that.

$ git rebase -i HEAD~5

git awsome-ness contains an example.

  1. Don't use git-rebase on public (remote) commits.
  2. Make sure your working directory is clean (commit or stash your current changes).
  3. Run the above command. It launches your $EDITOR.
  4. Replace pick before C and D by squash. It will meld C and D into B. If you want to delete a commit then just delete its line.

If you are lost, type:

$ git rebase --abort  

However, to copmress the .git folder safely, the above is not recommended. You can try the following as mentioned in a comment by Linus.

git repack -a -d --depth=250 --window=250

where that depth thing is just about how deep the delta chains can be (make them longer for old history - it's worth the space overhead), and the window thing is about how big an object window we want each delta candidate to scan.

Community
  • 1
  • 1
Pulkit Goyal
  • 5,365
  • 1
  • 25
  • 48
  • 1
    `git rebase` will completely rewrite history of commits making a lot of troubles for all ppl who already pulled from that repository. I don't think that's the right way to reduce size of `.git` directory. – KL-7 Jan 23 '12 at 09:53
  • I'm not sure but after I do git repack nothing is changing and I even do not need to push. Next time I want to clone already cleaned repository. – cnd Jan 23 '12 at 10:46
  • Since you don't want to keep track of the old commits, I think `git-rebase` is the correct choice for you. You can however try using `git gc --aggressive --prune` first to see if it helps. – Pulkit Goyal Jan 23 '12 at 10:53
3

Run git gc --help to get documentation.
In your case git gc --aggressive --prune will be good.

vpatil
  • 2,962
  • 1
  • 15
  • 9
1

Maybe you can try with:

$ git gc --auto

Man page says:

Runs a number of housekeeping tasks within the current repository, such as compressing file revisions (to reduce disk space and increase performance) and removing unreachable objects which may have been created from prior invocations of git add.

Users are encouraged to run this task on a regular basis within each repository to maintain good disk space utilization and good operating performance.

It's just a suggestion, I never have the need to use gc.

Community
  • 1
  • 1