Fixing git-annex repository
How to get out of trouble with git-annex
As I mentioned before I rely on git annex to take care of my data. Especially for things which I don’t always need on my laptop but which I’m unwilling to delete.
The most important thing is my collection of photos. Recently I was restructuring it. Moving files around and creating the uniform directory structure.
I should have been using git commands (like git mv
) to go about that restructuring. Unfortunately, I used regular mv
and cp
which meant I broke git-annex repository.
Let me explain how git-annex works.
By default when you add something to git-annex it will replace the file with a symlink. It will be pointing to a special place in .git
directory. It’s a simple and efficient solution.
If you move any of those symlinks with git commands everything will be fine.
In most cases touching them with non-git commands also doesn’t cause problems, as what matters for git-annex is where those links point to and not what they are named.
From the nature of symlinks if you move them in a directory hierarchy they will be broken because they will be pointing to the wrong thing.
And that’s exactly what I did.
At that point, normally, I would panic worried that I either lost my files or lost my work organizing it all. But I didn’t. Knowing that the files are safe in git-annex repository I could always revert the latest commit to getting the symlinks back. And if that would fail I had the copy of my disk from couple hours earlier, which meant that I could recover it from there.
After a little bit of googling I found the page on git-annex site with a hint how to fix my problem.
Turns out git-annex has a nifty command git annex fix
which would fix the symlinks. The only requisite for it to work was that the symlink needs to be known by git. Quick git add
for those files fixed that problem.
After git add
I run git annex fix
and all my photos were once again accessible.