Remove git-annex repository from file tree Remove git-annex repository from file tree git git

Remove git-annex repository from file tree


Okay, so I stumbled upon some docs for git-annex, and they give two commands that achieve what I wanted to do:

unannex [path ...]

Use this to undo an accidental git annex add command. You can use git annex unannex to move content out of the annex at any point, even if you've already committed it. This is not the command you should use if you intentionally annexed a file and don't want its contents any more. In that case you should use git annex drop instead, and you can also git rm the file.

uninit

Use this to stop using git annex. It will unannex every file in the repository, and remove all of git-annex's other data, leaving you with a git repository plus the previously annexed files.

I started running git annex uninit, but my god was it slow. It took about 5 minutes to "unannex" just a single file. My filesystem tree is about 200,000 files, so that was just unacceptable.

What I ended up doing was actually surprisingly simple and worked well. I used the cp -rL flags to automatically duplicate the contents of my file tree and reverse all symlinks in the duplicate copy. And it was blazing fast: around 30 seconds for my entire file tree. Only problem was that the file permissions were not retained from my original state, so I needed to run some chmod and chcon commands to fix up the permissions.

This second method worked for me because there were no other symlinks in my schema. If you do have symlinks in your schema beyond those created by git-annex, then my little shortcut probably isn't the right choice for you, and you should consider sticking with just git annex uninit.


I would like to include my own experience of using git annex uninit, in addition to OP's answer.

I didn't have full repository annexed, but only about 40 bigger files. After deciding that I have no particular benefit of using git-annex, I tried unannexing several files and it was over in several seconds per file. Then, I ran git annex uninit and it took more than a minute only for really huge files (more than few GB). Overall, it was done in about 20 minutes, which was acceptable in my case.

So, it seems that the complexity of unannexing increases with the size of annexed file tree.


If you have a v6 repository, you can do the following:

git unnannex . --fast

which replaces the symlinks w/ hardlinks instead of slowly replacing the symlinks with the original files again.

Only v6 repositories can execute the git-annex unannex command on uncommited changes, so it could be necessary to upgrade the git-annex repo to a v6 repository.

See the Official Upgrade Guide.

In my case I had to upgrade v5 -> v6 and I only had to executegit annex upgradewhich took a few seconds and I was done.