Notes on undeleting files in git-annex
Published: Friday, May 8, 2015 Last modified: Friday, May 12, 2023
Deleting a file in my media workflow
git ls-files $file --error-unmatch && git annex metadata -t drop $file && git rm $file
git ls-files $file --error-unmatch checks $file is actually in git. I make
the assumption here that if the file is in git, then it has been already added to git-annex.
git annex metadata -t drop $file tags the file as dropped. This is useful if
I accidentally import or copy it in again.
git rm $file actually deletes the file
UN-deleting a file
git reset HEAD $file git checkout HEAD $file
To make sure everything is OK, you must
git annex add and
git commit before deleting!!
Otherwise you will get confusing
error: pathspec '$file' did not match any file(s) known to git. messages.
IIUC if you delete a file that just
git annex add, it is possible you can
fish it out of
.git/annex/objects but the filename would be obfuscated.
git log --stat git-annex &
git-log --name-only git-annex will give you
visibility of the internals.
Remove contents of deleted file
This removes all “drop” tagged media:
git annex drop --metadata=tag=drop --force