Re: Question about removing old objects
From: Steven Grimm <hidden>
Date: 2016-06-15 22:43:06
John Wiegley wrote:
Hello, I am thinking of using git to track my home directory. However, rather than keeping old history around forever, I'd like to physically remove old objects after X days -- in essence, causing the repository to appear as if it had begun life X days ago. Is there a git command to do this?
Not exactly, but you can fake it using shallow clones. Something like this, assuming you do one revision per day and want to keep 10 days around (if you commit at irregular intervals, you'll have to do some scanning to figure out how deep to make the clone): # Go to the top level of your home-dir repo cd $HOME # Shallow clone the home-directory repo into a temporary one git clone --depth 10 -n . .temp-repo # Replace the home directory's repo with the shallow clone rm -rf .git.old mv .git .git.old mv .temp-repo/.git . # Since we did clone -n, there's nothing left in .temp-repo rmdir .temp-repo # Make the shallow clone cloneable so we can do this again tomorrow rm -f .git/shallow I haven't tried that exactly, but I think it should work. Of course, the final step removes a safety measure from the clone: you are technically not supposed to clone a shallow repo since it has an incomplete history and merges will probably fail horribly. But if, as it sounds like may be the case, you only ever have one copy of the repo anyway, I believe that should be harmless. If you're doing lots of branching and merging of your home directory then all bets are off. A more experienced git user than me will probably tell you (and me) if I've suggested something stupid there, so you might want to wait for some replies to this message before you start relying on that procedure. -Steve