在某些情况下,它无法存储整个git历史记录(例如build-bot)。
是否可以对git存储库进行浅层克隆(例如,使用单个分支master
),并保持最新状态,同时保持浅层状态?
答案 0 :(得分:4)
是的,这是可能的,以下git-commands是shell脚本函数,但实际上它们可能是bat文件或类似文件。
# clone
function git_shallow_clone() {
git clone --depth 1 --single-branch $@
}
# pull
function git_shallow_pull() {
g pull --no-tags $@
# clean-up, if a new revision is found.
git show-ref -s HEAD > .git/shallow
git reflog expire --expire=0
git prune
git prune-packed
}
# make an existing clone shallow (handy in some cases)
function git_shallow_make() {
# delete all branches except for the current branch
git branch -D `git branch | grep -v $(git rev-parse --abbrev-ref HEAD)`
# delete all tags
git tag -d `git tag | grep -E '.'`
# delete all stash
git stash clear
# clean-up, if a new revision is found. (same as above)
git show-ref -s HEAD > .git/shallow
git reflog expire --expire=0
git prune
git prune-packed
}
# load history into a shallow clone.
function git_shallow_unmake() {
git fetch --no-tags --unshallow
}
--no-tags
非常重要,否则您可以克隆sha1
指向blob位于分支master
之外的标记。master
感兴趣,或者至少对一个分支感兴趣。感谢:https://stackoverflow.com/a/7937916/432509(对于此答案的重要部分)