Since all the annexed (in indirect mode) files are symlinks to topdir/.git/annex/... moving files among directories at different levels is not that straightforward since symlinks would get broken. And since there is not 'annex mv' command -- what is the best way? (unlock is not the resolution since it copies the file, which might be prohibitively large and inefficient)
You can move the symlinks however you like (git mv, or regular mv and git add).
To fix up broken symlinks, you can either run
git annex fix
, or just commit the move. The pre-commit hook fixes up links automatically.I couldn't find an explanation for this using the search bar, so I thought this would be as good a place as any to ask this.
Even when I run
git mv
on git annexed file, git annex always changes it for what looks like a combo ofgit rm old_symlink; git add new_symlink
I guess it does this when that pre-commit hook you mentioned runs. Why?
Correction:
Why do moves that require changes to the symlinks to change result in a delete+add combo?
Code to reproduce just for the sake of completion:
I'm sorry if this has been already explained previously. I couldn't find it.
Git tracks the symlink. After your first commit, here's what is tracked for protein/milk:
And after your second commit:
Note that it's exactly the same content, and Git will (by default) present it as a rename.
In your final commit, the link that Git tracks changes:
Notice that the leading part of the link changed, corresponding to the movement out of the subdirectory.
mv
command for such moves withgit mv
. It partially solves the issue - git detects such moves as renames. But because git annex makes "fixup" for symbolic links in pre-commit hook, then git detects file change as well. A workaround to this might be separating those operations into two commits - one with rename and another one with symlink fixup. However, I wish it were possible to do this in a cleaner way.Managed to find a semi-satisfactory approach to solve this rename problem:
git mv
--no-verify
(e.g.git commit --no-verify
)Now, renamed symlinks should be broken, because we skip
git annex
hooks with--no-verify
.To fix it for the last commit, run:
And then do a commit again with whatever message you like (mine is
git commit -m "Fix git-annex symlinks"
).There are a couple of inconveniences here:
git commit
Hoverer, #2 is pretty easy to solve by running:
Though, not sure yet how to deal with #1 - probably there is a way to automate it.