threads / discuss / 16575

Is there a way to control the number of revisions will be saved by git

Subject: Is there a way to control the number of revisions will be saved by git

## tl;dr

9 messages between Dec 3, 2008 and Dec 3, 2008.

replies: 8people: 6as markdown or json

Tzury Bar Yochay· Dec 3, 2008, 11:01 UTC · lore
Hello Happy Gitters,

Say I wish to save only 100 generations back (per branch). Is it possible to configure git so it will save only N records back.

If git cannot be configured for that, Is there a way to shrink the repository manually so it will contain the last N generations?

- Tzury
Johannes Sixt· Dec 3, 2008, 11:22 UTC · re: Tzury Bar Yochay · lore

Re: Is there a way to control the number of revisions will be saved by git

Tzury Bar Yochay schrieb:
> Hello Happy Gitters,
> 
> Say I wish to save only 100 generations back (per branch).
> Is it possible to configure git so it will save only N records back.
No.
> If git cannot be configured for that, Is there a way to shrink the repository
> manually so it will contain the last N generations?
Yes:
  $ git rev-parse HEAD~$N >> .git/info/grafts
  $ git filter-branch HEAD

This assumes that your history is strictly linear and you do not have tags. It also rewrites the $N commits so that they now have different SHA1s. For this reason, don't share this repository with anyone - it leads to confusion.

-- Hannes
Jakub Narebski· Dec 3, 2008, 12:58 UTC · re: Johannes Sixt · lore

Re: Is there a way to control the number of revisions will be saved by git

Johannes Sixt <j.sixt@viscovery.net> writes:
> Tzury Bar Yochay schrieb:
> > Say I wish to save only 100 generations back (per branch).
> > Is it possible to configure git so it will save only N records back.
Why would you want that, by the way?
Show 14 quoted lines
> No.
> 
> > If git cannot be configured for that, Is there a way to shrink the
> > repository manually so it will contain the last N generations?
> 
> Yes:
> 
>   $ git rev-parse HEAD~$N >> .git/info/grafts
>   $ git filter-branch HEAD
> 
> This assumes that your history is strictly linear and you do not have
> tags. It also rewrites the $N commits so that they now have different
> SHA1s. For this reason, don't share this repository with anyone - it leads
> to confusion.
Or just use shallow clone
  git clone --depth <depth> <repository>

to have new copy (clone) of <repository> to have only <depth> commits back. See man git-commit; but it might be not what you want.

-- 
Jakub Narebski
Poland
ShadeHawk on #git
Miklos Vajna· Dec 3, 2008, 13:40 UTC · re: Jakub Narebski · lore

Re: Is there a way to control the number of revisions will be saved by git

On Wed, Dec 03, 2008 at 04:58:40AM -0800, Jakub Narebski <jnareb@gmail.com> wrote:
Show 6 quoted lines
> Or just use shallow clone
> 
>   git clone --depth <depth> <repository>
> 
> to have new copy (clone) of <repository> to have only <depth> commits
> back.  See man git-commit; but it might be not what you want.
You mean man git-clone?
This trick can be used only once, since you can't clone a shallow clone.
Arafangion· Dec 3, 2008, 11:37 UTC · re: Tzury Bar Yochay · lore

Re: Is there a way to control the number of revisions will be saved by git

On Wed, 2008-12-03 at 13:01 +0200, Tzury Bar Yochay wrote: <snip>

> Say I wish to save only 100 generations back (per branch).
> Is it possible to configure git so it will save only N records back.

What would be the advantage in doing that? Git is designed so that you have all your history available, and saves data in such a way that it really doesn't take much space.

How would git be able to perform a merge from one branch to another if it didn't have this history available?

That said, you could probably chop off the history you don't want by doing tricks with grafting, and rewriting all your history, but this would likely use more disk space because your branches wouldn't have anything in common, and also make it very difficult to merge in the future.

Jean-Luc Herren· Dec 3, 2008, 13:04 UTC · re: Arafangion · lore

Re: Is there a way to control the number of revisions will be saved by git

Arafangion wrote:
Show 6 quoted lines
> On Wed, 2008-12-03 at 13:01 +0200, Tzury Bar Yochay wrote:
> <snip>
>> Say I wish to save only 100 generations back (per branch).
>> Is it possible to configure git so it will save only N records back.
> 
> What would be the advantage in doing that?

That would be a shallow repository, as is already supported by "git clone --depth 100". It can be useful for a number of things, for example developing simple patches on top of HEAD and sending them somewhere.

What the OP might want is a way to convert a full repository into a shallow one (can be done by cloning and deleting the original), and then be able to make it shallower from time to time, to limit it to 100 revisions; not sure if that is possible.

jlh
Tzury Bar Yochay· Dec 3, 2008, 18:23 UTC · re: Tzury Bar Yochay · lore

Re: Is there a way to control the number of revisions will be saved by git

On Wed, Dec 3, 2008 at 8:20 PM, Tzury Bar Yochay <tzury.by@gmail.com> wrote:
>> Why would you want that, by the way?
> I was thinking of building some experimental application on top of git
>

Looking at the numbers (of bytes). GIT's efficiency seems to redundant this option which was a result of my concern about disk space usage.

GIT creators are magicians!

← back to recent threads