Git中ALTERNATE_DB_ENVIRONMENT环境变量设置备用对象目录失效求助
根据Git源码中object-file.c的注释,设置ALTERNATE_DB_ENVIRONMENT环境变量应该可以替代.git/objects/info/alternates文件来配置备用对象目录。注释内容如下:
The elements on this list come from non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates, whose contents is similar to that environment variable but can be LF separated.
Its base points at a statically allocated buffer that contains "/the/directory/corresponding/to/.git/objects/...", while its name points just after the slash at the end of ".git/objects/" in the example above, and has enough space to hold all hex characters of the object ID, an extra slash for the first level indirection, and the terminating NUL.
但实际测试中,该环境变量无法生效,而使用.git/objects/info/alternates文件的方法可以正常工作。
复现步骤
创建备用对象数据库
cd $HOME mkdir -p .cache/git cd .cache/git git init --bare git remote add bdwgc https://github.com/ivmai/bdwgc git fetch --all
使用ALTERNATE_DB_ENVIRONMENT环境变量的失效方法
export ALTERNATE_DB_ENVIRONMENT=$HOME/.cache/git/objects cd /tmp mkdir bdwgc cd bdwgc git init git fetch https://github.com/ivmai/bdwgc
使用.git/objects/info/alternates文件的有效方法
cd /tmp mkdir bdwgc cd bdwgc git init echo "$HOME/.cache/git/objects" >> .git/objects/info/alternates git fetch https://github.com/ivmai/bdwgc
注:两种方式均使用绝对路径,例如/home/nfl/.cache/git/objects
请问我哪里操作有误?
内容的提问来源于stack exchange,提问作者nfl

