这将使您拥有一个带有相关 S3 存储桶的 git 存储库“myrepo”,其中包含您的 git 存储库中您并不真正想要的所有大文件。
设置回购:
# Clone your repo "myrepo"
git clone git@github.com:me/myrepo.git
cd myrepo
# Initialize it to work with git-annex.
# This creates .git/annex directory in the repo,
# and a `git-annex` metadata branch the tools use behind the scenes.
git annex init
# The first time you use the repo with git-annex someone must link it to S3.
# Be sure to have AWS_* env vars set.
# Select a name that is fitting to be a top-level bucket name.
# This creates the bucket s3://myrepo-annexfiles-SOME_UUID.
git annex initremote myrepo-annexfiles type=S3
# Save the repo updates related to attaching your git annex remote.
# Warning: this does a commit and push to origin of this branch plus git-annex.
# It will ALSO grab other things so make sure you have committed
# or stashed those to keep them out of the commit.
git annex sync
在附件中添加一些文件:
# These examples are small for demo.
mkdir mybigfiles
cd mybigfiles
echo 123 > file1
echo 456 > file2
# This is the alternative to `git add`
# It replaces the files with symlinks into .git/annex/.../SOME_SHA256.
# It also does `git add` on the symlinks, but not the targets.
git annex add file*
# Look at the symlinks with wonder.
ls -l mybigfiles/file*
# This puts the content into S3 by SHA256 under the attached to your "special remote":
git annex move file* --to myrepo-annexfiles
# Again, this will do a lot of committing and pushing so be prepared.
git annex sync
使用git-annex
git repo 将只有包含真实文件内容的 SHA256 值的死符号链接,并且该工具将关闭大文件。
后来,当其他人克隆 repo 并想要文件时:
git clone myrepo
cd myrepo
# Enable access to the S3 annex files.
# NOTE: This will put out a warning about ssh because the origin above is ssh.
# This is ONLY telling you that it can't push the big annex files there.
# In this example we are using git-annex specifically to ensure that.
# It is good that it has configured your origin to NOT participate here.
git annex enableremote myrepo-annexfiles
# Get all of the file content from S3:
git annex get mybigfiles/*
完成文件后,取回磁盘空间:
git annex drop mybigfiles/*
检查所有内容的真实位置,以及真正下载的位置:
git annex whereis mybigfiles/file*
请注意,git-annex 是一个超级灵活的工具。我发现为常见案例提炼出一个更简单的方法需要对文档进行一些研究。希望这对其他人有帮助。