6

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?

Hamza Yerlikaya
  • 49,047
  • 44
  • 147
  • 241

4 Answers4

4

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
  • 89,080
  • 21
  • 111
  • 133
3

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.

Community
  • 1
  • 1
Dan Moulding
  • 211,373
  • 23
  • 97
  • 98
2

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.

Jim Mitchener
  • 8,835
  • 7
  • 40
  • 56
  • 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 Dec 08 '09 at 21:49
  • 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. – Jim Mitchener Dec 08 '09 at 22:16
2

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

Greg McGary
  • 3,334
  • 1
  • 15
  • 2
  • when pulled from other repos that would also sync, yes? – Hamza Yerlikaya Dec 09 '09 at 23:25
  • 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 Dec 11 '09 at 23:43