我知道如果在裸仓库中有文件,可以使用 git show HEAD:path/to/file
来访问它们。
但是,我能否在不克隆和修改工作树的情况下向裸仓库添加新内容呢?
我知道如果在裸仓库中有文件,可以使用 git show HEAD:path/to/file
来访问它们。
但是,我能否在不克隆和修改工作树的情况下向裸仓库添加新内容呢?
#!/bin/sh
cd ~server
# supply locations git ordinarily does on its own in working i.e. non-bare repos:
export GIT_DIR=$PWD/repo.git # bare repos don't have defaults for these
export GIT_WORK_TREE=$PWD # so supply some to suit our purpose
export GIT_INDEX_FILE=$GIT_DIR/scratch-index # ...
# payload: commit (only) the latest file in data/logs:
git read-tree --empty # make the index all pretty, and
git add data/logs/`ls -1t data/logs|sed q` # everything's ordinary from here - add and
git commit -m'new logfile' # commit
git read-tree
从提交的树中加载索引条目。它是 checkout、merge 和 reset 的基础,可能还有一些我暂时忘记的功能。在这里,我们只想要一个空的索引来开始,因此使用 --empty
。
使用 push/pull/remote 同步数据,同时使用每台机器上已经可用的工具
你说过随着时间的推移会有“数百万”个文件,如果你不想分发完整的历史记录,那么像你已经怀疑的那样,rsync
可能是更好的选择。但是,如果每分钟只传输一个新文件,那么累积一百万个文件需要两年时间。所以,?
无论如何,上述过程对于每次提交的小规模文件非常高效可扩展。对于大量工作,有更好的方法。