Remove old versions of a file #5651
-
Hi, I've been trying to get rid of old versions of files in lfs storage. My strategy is the following:
Unfortunately, I think there is no way around 2, but that's not my current issue. Thing is I'm stuck at 1. For example, to remove all but the last version of test.txt I'm doing this:
Where
Another thing I tried is to prune the repo with I would like to cleanly prune contents and pointers so that in the end I have a repo that is the same than the original except that ancient versions of lfs content have been removed. Thank you in advance, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Here is a detailed example of the procedure I'm following to get rid of old versions by pruning, notice how it fails at the end.
For some reason 7de1555df0 wasn't pushed to the new remote, even though it exists locally at r/.git/lfs/objects. EDIT: I was able to get it pushed by running EDIT: moreover, this strategy fails when I want to checkout a revision that has a dangling pointer:
This makes sense but goes against my goal. Ideally it should work as if test.text was never there. It not, at least it should checkout the pointer file without failing. |
Beta Was this translation helpful? Give feedback.
-
Here is another alternative that I've been thinking about, in order to avoid having to deal with pointers and pointees while filtering:
I've not tested this approach yet. But do you think it's sensible? Or maybe overkilling? |
Beta Was this translation helpful? Give feedback.
-
Hey, thanks for the question and detailed descriptions of the approaches you've tried. If I understand correctly, you're hoping to rewrite earlier commits in your Git history to remove Git LFS objects in those commits. I think the key point is that, assuming you want a "clean" history where you can checkout any particular commit without problems, you'll have to decide if those earlier commits should have (a) the original file, not converted to a Git LFS object, or (b) no file at all. If you leave Git LFS pointers in the history but remove all copies of the corresponding objects, I suspect you'll keep running into the problem you mentioned, i.e., you can't check out a commit with some Git LFS pointer files without the Git LFS client complaining:
Here's a working example of a simple repo, derived from yours above, where we just remove the files entirely from earlier commits.
However, this is a very restricted example. Using Also, the example simply adds Personally, I think your proposal to use |
Beta Was this translation helpful? Give feedback.
-
Thank you for the detailed and kind answer, it was worth the wait. I'll go with the export/import approach then. |
Beta Was this translation helpful? Give feedback.
Hey, thanks for the question and detailed descriptions of the approaches you've tried.
If I understand correctly, you're hoping to rewrite earlier commits in your Git history to remove Git LFS objects in those commits. I think the key point is that, assuming you want a "clean" history where you can checkout any particular commit without problems, you'll have to decide if those earlier commits should have (a) the original file, not converted to a Git LFS object, or (b) no file at all. If you leave Git LFS pointers in the history but remove all copies of the corresponding objects, I suspect you'll keep running into the problem you mentioned, i.e., you can't check out a commit with some Git …