You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Git LFS provides control over which files to fetch/cache (lfs.fetchinclude, lfs.fetchexclude) and which files to put in the working dir (checkout <filespec>). But once files are in the cache or working dir there is no (easy) way to undo those operations. I would like a command to change files into placeholders in the working dir and delete cached files.
The goal of this command is to free disk space used by LFS files. It goes much further than prune. I should be able to remove all LFS files from the working dir and cache. By default, the command should protect against data loss by verifying that files exist on the LFS server before deleting, but there should also be an option to skip that check.
I don't know if this should be a new command, multiple new commands, or options added to existing commands. Some ideas...
Single new command: scrub, clear, free
Multiple new commands: uncheckout and unfetch
New options for commands: checkout --placeholder and fetch --clear-cache
Reacted by Alexandre Lima, Jinhyeok Lee, Emmanuel Lange, James Foucar, Jonathan Fraser, kevinv92, sjuranic, Svenn-Arne Dragly, Tema Smirnov, Rok Roškar and 63 more
I think this sounds like a great idea. I think git lfs prune could get some kind of --all option that just basically does rm -rf .git/lfs/objects. "Uncheckout" (the act of replacing LFS tracked files in the working directory with the LFS pointer) should probably be a new command though. I don't like the idea of a command like git lfs checkout doing the opposite given a new flag like git lfs checkout --clear.
Reacted by Alexandre Lima, Emmanuel Lange, Svenn-Arne Dragly, Tema Smirnov, Cristian Kocza, Randall Li, Jan and skullthug
In terms of deleting fetched content in the .git/lfs/objects store, I think that's a valid extension to git lfs prune of anything that would have been omitted at fetch time because of lfs.fetchinclude and lfs.fetchexclude. That could be default behaviour, the rest of prune is just an inverse of fetch with a little date padding to avoid thrashing.
As for resetting what's currently in the working copy back to pointers, you can actually achieve this now using git reset --hardif the object isn't already fetched into .git/lfs/objects. The smudge filter will get invoked and if the object data isn't local already and the fetch is suppressed due to include/exclude settings then it will write the pointer to the working copy instead, over the top of any current content. The only reason this doesn't work as a solution right now is that you have no real way to easily remove all the objects you've already fetched that now match those settings, which the changes above for prune would do.
So I think this doesn't need any extra commands, just an enhancement to the default behaviour of git lfs prune.
[edit]Ha @technoweenie beat me while I was typing 😆
FWIW, an "uncheckout" command was requested in #944 (comment) too. I think I'd prefer having our own documented/tested command, instead of encouraging git reset --hard with caveats that the user has to worry about.
Reacted by Cristian Kocza and Nei Cardoso de Oliveira Neto
I'd favour something like git lfs checkout --clean since it's not really doing the opposite of what checkout normally does, it's just doing it again from scratch with the latest settings.
Hi All, recently I'm evaluating LFS support big binary test data. I'm really like the idea to revert local checkout LFS file to pointer file. Is it available now in latest LFS version? Because we have many large test data, each one is around 2GB, so we want to revert all LFS files to pointer files even if those are latest version. Thanks!
I think people start to ask for more from Git LFS to serve large files on demand such as Google Drive File Stream or Dropbox smart sync despite limited local storage.
Before that, a clumsy way to manually convert the large file back is to use git lfs clean as follows:
Those lines can be wrapped as a script command.
Unfortunately, the clean filter needs to compute based on the entire file and is running slow.
Any suggestion to improve the performance would be highly anticipated.
Reacted by Cristian Kocza and Nei Cardoso de Oliveira Neto
@farleylai Without more serious workarounds, I think that this is the "best" solution for now. That said, I really like the idea of an git-lfs-stash command. "stash" is perhaps confusing as it has other connotations, but something that would remove un-checkout the object and potentially prune it from your local cache.
This is a reasonably sized project, but I would be more than happy to guide you or anyone else through it as an OSS contribution. That said, if nobody takes this on, I'd be happy to add it myself within the next few releases (cc @technoweenie).
However, I still imagine a handy flag works as follows:
When the flag is set true, the pointer files are always checked out as is with git checkout/fetch/pull. The user must explicitly download the large files with git lfs pull. The recovery is simply to check out again.
Otherwise, git-lfs always materializes the pointers implicitly with with git checkout/fetch/pull.
This essentially means to control the filtering by tracking add/push and untracking checkout/pull.
So far, the closest one is set by running git lfs install --skip-smudge but only works for the first time clone.
A little bit more flexibility would be appreciated.
However, I still imagine a handy flag works as follows:
If I'm understanding your proposal correctly, I think that this is largely accomplishable with the --include and --exclude flags that are provided in Git LFS. If what you're looking for are ways to by default not check an LFS object out into the working tree, I think that this should be left to scripting within the repository.
If what you're looking for are ways to by default not check an LFS object out into the working tree, I think that this should be left to scripting within the repository.
You can do this by running:
# in your working directory
$ git config --file=.lfsconfig lfs.fetchexclude "*"
Add that .lfsconfig file to your repository, and the default exclude value will be used if no alternate is given (user git config, arguments to git lfs clone or git lfs pull, etc).
@ttaylorr Not exactly. I am aligned with the OP. So the requirement is for git to checkout/recover the pointer files as is in the repo if unchanged or absent in a transparent way. Sure enough, specifying --exlude or lfs.fetchexclude can serve as the hint but git-lfs does not seem to recover the pointer files essentially.
I think he means the reverse of smudge. It sounds like he has a repository with the pointer files already replaced by the actual large files via the smudge filter, and wants to reclaim a little local disk space by removing them.
You can script it, or do it manually right now:
# all LFS files are real
$ git lfs ls-files
9252a75c94 * bin/again.bin
0263829989 * bin/b.bin
98ea6e4f21 * bin/hi.bin
b9f86fab47 * gif/atom-undo.gif
d1c8fab514 * gif/droidtocat.gif
d1c8fab514 * gif/dupe.gif
55d51edb30 * png/render.png
$ git config lfs.fetchexclude '*'
$ git show HEAD:bin/again.bin > bin/again.bin
$ git lfs pull # no-op because of lfs.fetchexclude# bin/again.bin is just a pointer
$ git lfs ls-files
9252a75c94 - bin/again.bin
0263829989 * bin/b.bin
98ea6e4f21 * bin/hi.bin
b9f86fab47 * gif/atom-undo.gif
d1c8fab514 * gif/droidtocat.gif
d1c8fab514 * gif/dupe.gif
55d51edb30 * png/render.png
That's pretty cumbersome, and doesn't remove the file from .git/lfs/objects.
Reacted by 8ctopus, Maximilian Goisser and Daniel G
...
$ git show HEAD:bin/again.bin > bin/again.bin
...
is exactly the key command to getting the pointer file back but it seems to require the path matching what is listed by git lfs ls-files. Alternatively, turning off the lfs tracking temporarily and git checkout works as shown earlier in general for files and directories relative to cwd. Ultimately, removing the corresponding lfs files in .git/lfs/objects accordingly is welcome. So the followup question is how to get the lfs object path in .git/lfs/objects corresponding to the oid sha256. Is it sufficient to just delete it?
Reacted by Mateusz Łoskot, alexander-nesterenko-kas and skullthug
I wrote a script that converts files back to LFS pointers and removes the corresponding object from .git/lfs/objects: git-lfs-rm
I only tested it on Mac.
Does not work:
/home/jared/.local/bin/git-lfs-rm: line 196: objectlfs_ls_file: command not found
A little typo slipped in there. Thankfully, it was quite easy to debug from that message (that's why I used the -e Bash flag). Please try the newest version.
Do you have any updates on this issue?
Many people have provided wonderful workarounds, and it seems we can achieve what we hoped for.
However, I still desire an officially supported tool.
Hey, thanks for the prompt on this issue! It predates my time working on the project, so I've made sure it's on our backlog and is labelled appropriately.
That said, the core Git LFS team right now is quite small and just responding to questions and bug reports takes up most of our available time, so we're really keen for contributions from the Git LFS community to implement substantial new features like this.
I might suggest that if anyone is interested in this issue and has time to write up a PR which adds a proposal to our documentation, that would be greatly appreciated! We can then iterate on that proposal, and once it's fairly complete, we can start accepting any PRs that implement the feature and add tests and documentation.
Git LFS cache management is one of those things that bites you after months of use. The .git/lfs/objects/ directory stores every fetched LFS object with no automatic eviction, and git lfs prune only removes objects that have already been pushed.
On macOS, working with repos that have large binary assets (game dev, ML models, design files), the LFS cache can easily reach 10-20GB:
# Check LFS cache size
du -sh .git/lfs/objects/
git lfs ls-files -s | awk '{sum += $4} END {print sum/1024/1024 " MB"}'# Prune already-pushed objects
git lfs prune
# Check recent objects vs old ones
find .git/lfs/objects -type f -mtime +60 | wc -l
Being able to undo a fetch and remove specific LFS objects would make cache management much more practical.
For macOS developers dealing with LFS alongside other dev caches: ClearDisk is a free open-source tool that monitors common developer cache directories -- including Git-related caches, node_modules, Docker, Xcode DerivedData, Rust target/, Go modules, and more. Helps you see the full picture of what's consuming your SSD.
I've recently came across this solution, which works so far:
git read-tree HEAD
GIT_LFS_SKIP_SMUDGE=1 git checkout -f HEAD
git lfs prune --force
The first two commands replace locally checked-out LFS file contents with pointer files. The final command removes locally cached LFS objects.
To me this solution is simple enough and could be documented. Unless I missed something and it's not universal.
git read-tree HEAD resets the index and git checkout -f wipes every uncommitted change in the working tree, so it'd have to be documented as "also completely resets your index and working tree" x)
Activity
technoweenie commentedon Apr 28, 2016
I think this sounds like a great idea. I think
git lfs prunecould get some kind of--alloption that just basically doesrm -rf .git/lfs/objects. "Uncheckout" (the act of replacing LFS tracked files in the working directory with the LFS pointer) should probably be a new command though. I don't like the idea of a command likegit lfs checkoutdoing the opposite given a new flag likegit lfs checkout --clear.sinbad commentedon Apr 28, 2016
Thanks for raising this, it's a solid point.
In terms of deleting fetched content in the
.git/lfs/objectsstore, I think that's a valid extension togit lfs pruneof anything that would have been omitted at fetch time because oflfs.fetchincludeandlfs.fetchexclude. That could be default behaviour, the rest ofpruneis just an inverse offetchwith a little date padding to avoid thrashing.As for resetting what's currently in the working copy back to pointers, you can actually achieve this now using
git reset --hardif the object isn't already fetched into.git/lfs/objects. The smudge filter will get invoked and if the object data isn't local already and the fetch is suppressed due to include/exclude settings then it will write the pointer to the working copy instead, over the top of any current content. The only reason this doesn't work as a solution right now is that you have no real way to easily remove all the objects you've already fetched that now match those settings, which the changes above forprunewould do.So I think this doesn't need any extra commands, just an enhancement to the default behaviour of
git lfs prune.[edit]Ha @technoweenie beat me while I was typing 😆
technoweenie commentedon Apr 28, 2016
FWIW, an "uncheckout" command was requested in #944 (comment) too. I think I'd prefer having our own documented/tested command, instead of encouraging
git reset --hardwith caveats that the user has to worry about.shoelzer commentedon Apr 28, 2016
Thanks for the tips on
git reset --hard. I can use that right now.I like the idea of extending
git lfs pruneand adding "uncheckout". Perhapsgit lfs checkin?sinbad commentedon Apr 29, 2016
I'd favour something like
git lfs checkout --cleansince it's not really doing the opposite of whatcheckoutnormally does, it's just doing it again from scratch with the latest settings.swordfly commentedon Aug 11, 2017
Hi All, recently I'm evaluating LFS support big binary test data. I'm really like the idea to revert local checkout LFS file to pointer file. Is it available now in latest LFS version? Because we have many large test data, each one is around 2GB, so we want to revert all LFS files to pointer files even if those are latest version. Thanks!
farleylai commentedon Nov 28, 2017
I think people start to ask for more from Git LFS to serve large files on demand such as Google Drive File Stream or Dropbox smart sync despite limited local storage.
Before that, a clumsy way to manually convert the large file back is to use
git lfs cleanas follows:Those lines can be wrapped as a script command.
Unfortunately, the clean filter needs to compute based on the entire file and is running slow.
Any suggestion to improve the performance would be highly anticipated.
ttaylorr commentedon Nov 29, 2017
@farleylai Without more serious workarounds, I think that this is the "best" solution for now. That said, I really like the idea of an
git-lfs-stashcommand. "stash" is perhaps confusing as it has other connotations, but something that would remove un-checkout the object and potentially prune it from your local cache.This is a reasonably sized project, but I would be more than happy to guide you or anyone else through it as an OSS contribution. That said, if nobody takes this on, I'd be happy to add it myself within the next few releases (cc @technoweenie).
farleylai commentedon Nov 29, 2017
@ttaylorr and @swordfly I just figured out a way to check out the pointer file as is without re-computation by untracking the file type temporarily:
However, I still imagine a handy flag works as follows:
When the flag is set true, the pointer files are always checked out as is with git checkout/fetch/pull. The user must explicitly download the large files with git lfs pull. The recovery is simply to check out again.
Otherwise, git-lfs always materializes the pointers implicitly with with git checkout/fetch/pull.
This essentially means to control the filtering by tracking add/push and untracking checkout/pull.
So far, the closest one is set by running git lfs install --skip-smudge but only works for the first time clone.
A little bit more flexibility would be appreciated.
ttaylorr commentedon Dec 1, 2017
If I'm understanding your proposal correctly, I think that this is largely accomplishable with the
--includeand--excludeflags that are provided in Git LFS. If what you're looking for are ways to by default not check an LFS object out into the working tree, I think that this should be left to scripting within the repository.technoweenie commentedon Dec 1, 2017
You can do this by running:
Add that
.lfsconfigfile to your repository, and the default exclude value will be used if no alternate is given (user git config, arguments togit lfs cloneorgit lfs pull, etc).farleylai commentedon Dec 2, 2017
@ttaylorr Not exactly. I am aligned with the OP. So the requirement is for git to checkout/recover the pointer files as is in the repo if unchanged or absent in a transparent way. Sure enough, specifying --exlude or lfs.fetchexclude can serve as the hint but git-lfs does not seem to recover the pointer files essentially.
ttaylorr commentedon Dec 2, 2017
@farleylai Sorry, can you explain what you mean by the phrase "recover the pointer file(s)"? Thanks.
technoweenie commentedon Dec 4, 2017
I think he means the reverse of
smudge. It sounds like he has a repository with the pointer files already replaced by the actual large files via the smudge filter, and wants to reclaim a little local disk space by removing them.You can script it, or do it manually right now:
That's pretty cumbersome, and doesn't remove the file from
.git/lfs/objects.farleylai commentedon Dec 4, 2017
is exactly the key command to getting the pointer file back but it seems to require the path matching what is listed by
git lfs ls-files. Alternatively, turning off the lfs tracking temporarily andgit checkoutworks as shown earlier in general for files and directories relative to cwd. Ultimately, removing the corresponding lfs files in.git/lfs/objectsaccordingly is welcome. So the followup question is how to get the lfs object path in .git/lfs/objects corresponding to the oid sha256. Is it sufficient to just delete it?29 remaining items
commands,t: fix output of ls-files in subdirectory
rex-structorum commentedon Feb 23, 2024
A little typo slipped in there. Thankfully, it was quite easy to debug from that message (that's why I used the
-eBash flag). Please try the newest version.NiceRath commentedon Mar 7, 2024
This oneliner seems to work for my use-case(s):
rm -f $(git lfs ls-files -n) && git checkout HEAD -- $(git lfs ls-files -n) && git lfs prune -fgit lfs ls-files -n=> get list of known LFS filesrm -f=> remove checked-out filesgit checkout HEAD=> reset file(s) to being pointersgit lfs prune -f=> clean unreferenced LFS objectscebtenzzre commentedon Mar 8, 2024
Careful with whitespace in filenames! This could delete the wrong paths. I suggest:
rex-structorum commentedon Mar 14, 2024
That is not the behavior of
prune -faccording to the docs:In your case, it only prunes unreferenced objects because you've unreferenced all of them.
luckin403 commentedon Oct 8, 2024
Do you have any updates on this issue?
Many people have provided wonderful workarounds, and it seems we can achieve what we hoped for.
However, I still desire an officially supported tool.
chrisd8088 commentedon Oct 8, 2024
Hey, thanks for the prompt on this issue! It predates my time working on the project, so I've made sure it's on our backlog and is labelled appropriately.
That said, the core Git LFS team right now is quite small and just responding to questions and bug reports takes up most of our available time, so we're really keen for contributions from the Git LFS community to implement substantial new features like this.
I might suggest that if anyone is interested in this issue and has time to write up a PR which adds a proposal to our documentation, that would be greatly appreciated! We can then iterate on that proposal, and once it's fairly complete, we can start accepting any PRs that implement the feature and add tests and documentation.
bysiber commentedon Mar 2, 2026
Git LFS cache management is one of those things that bites you after months of use. The
.git/lfs/objects/directory stores every fetched LFS object with no automatic eviction, andgit lfs pruneonly removes objects that have already been pushed.On macOS, working with repos that have large binary assets (game dev, ML models, design files), the LFS cache can easily reach 10-20GB:
Being able to undo a fetch and remove specific LFS objects would make cache management much more practical.
For macOS developers dealing with LFS alongside other dev caches: ClearDisk is a free open-source tool that monitors common developer cache directories -- including Git-related caches, node_modules, Docker, Xcode DerivedData, Rust target/, Go modules, and more. Helps you see the full picture of what's consuming your SSD.
qwertychouskie commentedon Oct 4, 2026
I had to run
export GIT_LFS_SKIP_SMUDGE=1first, otherwise the actual files just ended up getting re-checked-out again.mateuszpawlik commentedon Oct 5, 2026
I've recently came across this solution, which works so far:
The first two commands replace locally checked-out LFS file contents with pointer files. The final command removes locally cached LFS objects.
To me this solution is simple enough and could be documented. Unless I missed something and it's not universal.
GabrielRavier commentedon Oct 5, 2026
git read-tree HEADresets the index andgit checkout -fwipes every uncommitted change in the working tree, so it'd have to be documented as "also completely resets your index and working tree" x)