Kuba96
Kuba96

Reputation: 41

Removing versions of files older than 90 days in Git

I would like to find out if there is a way to remove certain versions of files that are older than 90 days using any settings or some kind of retention policy in Git?

Upvotes: 1

Views: 1460

Answers (2)

Lars Moelleken
Lars Moelleken

Reputation: 728

If you would like to remove the files with a new commit, here you go:

~/bin/git-delete-files-older-then.sh // <- copy and past the next code

#!/bin/bash                                                                      
                                                                                 
date=$1                                                                          
git ls-files | while read path                                                   
do                                                                               
  if [ "$(git log --since \"$date\" -- $path)" == "" ]; then                     
    rm "$path"                                                                   
  fi                                                                                                                                                                                                        
done  

chmod +x ~/bin/git-delete-files-older-then.sh

bash (or zsh ...)

cd /your/dir/YOUR_GIT_PROJECT/foo/

git-files-older-then.sh "2019-01-01" // this will delete all files in the "foo" directory older than "2019-01-01"

Upvotes: 2

bk2204
bk2204

Reputation: 76984

No, there isn't. Git is designed to preserve history indefinitely because the object ID of each commit is a cryptographic hash which implicitly covers the entire history up to that point.

There may be external tools to do this, but they will necessarily rewrite the entire history and change the hash of every commit.

If your goal is to remove some sensitive information, GitHub has documentation on how to do this and there are many other tools which can do so as well.

Upvotes: 3

Related Questions