summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Steve <Steve@web>2012-12-15 14:06:24 +0000
committerGravatar admin <admin@branchable.com>2012-12-15 14:06:24 +0000
commitc3da1354658b8a7dbe5d5f0422a239d75df52b6e (patch)
treec591ffb8ccfaf3cbbdc7e27e63203ce6ab893ac5
parentb03d905d759e6d177640917b33e8c5f4fbae0213 (diff)
-rw-r--r--doc/forum/How_to_retroactively_annex_a_file_already_in_a_git_repo.mdwn19
1 files changed, 19 insertions, 0 deletions
diff --git a/doc/forum/How_to_retroactively_annex_a_file_already_in_a_git_repo.mdwn b/doc/forum/How_to_retroactively_annex_a_file_already_in_a_git_repo.mdwn
new file mode 100644
index 000000000..97f5828d3
--- /dev/null
+++ b/doc/forum/How_to_retroactively_annex_a_file_already_in_a_git_repo.mdwn
@@ -0,0 +1,19 @@
+I worked out how to retroactively annex a large file that had been checked into a git repo some time ago. I thought this might be useful for others, so I am posting it here.
+
+Suppose you have a git repo where somebody had checked in a large file you would like to have annexed, but there are a bunch of commits after it and you don't want to loose history, but you also don't want everybody to have to retrieve the large file when they clone the repo. This will re-write history as if the file had been annexed when it was originally added.
+
+This command works for me, it relies on the current behavior of git which is to use a directory named .git-rewrite/t/ at the top of the git tree for the extracted tree. This will not be fast and it will rewrite history, so be sure that everybody who has a copy of your repo is OK with accepting the new history. If the behavior of git changes, you can specify the directory to use with the -d option. Currently, the t/ directory is created inside the directory you specify, so "-d ./.git-rewrite/" should be roughly equivalent to the default.
+
+Enough with the explanation, on to the command:
+<pre>
+git filter-branch --tree-filter 'for FILE in file1 file2 file3;do if [ -f "$FILE" ] && [ ! -L "$FILE" ];then git rm --cached "$FILE";git annex add "$FILE";ln -sf `readlink "$FILE"|sed -e "s:^../../::"` "$FILE";fi;done' --tag-name-filter cat -- --all
+</pre>
+
+replace file1 file2 file3... with whatever paths you want retroactively annexed. If you wanted bigfile1.bin in the top dir and subdir1/bigfile2.bin to be retroactively annexed try:
+<pre>
+git filter-branch --tree-filter 'for FILE in bigfile1.bin subdir1/bigfile2.bin;do if [ -f "$FILE" ] && [ ! -L "$FILE" ];then git rm --cached "$FILE";git annex add "$FILE";ln -sf `readlink "$FILE"|sed -e "s:^../../::"` "$FILE";fi;done' --tag-name-filter cat -- --all
+</pre>
+
+**If your repo has tags** then you should take a look at the git-filter-branch man page about the --tag-name-filter option and decide what you want to do. By default this will re-write the tags "nearly properly".
+
+You'll probably also want to look at the git-filter-branch man page's section titled "CHECKLIST FOR SHRINKING A REPOSITORY" if you want to free up the space in the existing repo that you just changed history on.