tags:

views:

76

answers:

4

I have one repository where a lot of large binary files live. Is it possibly set git to make it keep only last n number of commits? Such as i only want to keep last 5 copies of files in this repository history? But i would very like to not do this manually every 5 commits?

+1  A: 

Kindasorta. git clone --depth N will let you do a "shallow clone" of the repository. However, you cannot push/clone/fetch from this so it's not very useful as a developer.

jcm
i know about that but i also don't want to keep more than 5 copies in non of the repos, not just clones.
Hamza Yerlikaya
That is not possible, you will have to rewrite the repository as @Dustin is suggesting. I suggest you re-evaluate how you want to store these huge files. Perhaps Git is not the best solution.
jcm
+3  A: 

The only way to do that is to periodically rewrite the repository.

A commit contains a hash of the commit meta data, the commit info, the commit's parent(s) and the tree you're committing. It's not possible to change something in the past without affecting the present.

Dustin
+2  A: 

As Dustin mentioned, the only way to do that is to periodically rewrite the repository. Git definitely doesn't have "built-in" support for this, nor is likely to have such support any time soon (the fundamental design of the thing kind of precludes this feature). That means if you want to do it, you're going to have to do it manually.

If you want to give it a try, the answer to this question shows an example of how this can be done using git filter-branch.

Dan Moulding
+2  A: 

Use "git rebase --interactive". Mark the first five commits as "pick" and the remainder as "squash".

Greg McGary
when pulled from other repos that would also sync, yes?
Hamza Yerlikaya
Cloned directories will have to pull the complete changed history every time you change history, so a `git fetch` from a cloned repository might take some time--but yes, they will sync.
Bombe