[英]How to keep a shallow git clone up to date (while remaining shallow)
在某些情況下,存儲整個 git 歷史記錄(例如構建機器人)沒有用。
是否可以對 git 存儲庫進行淺層克隆(例如,具有單個分支, master
),並保持最新狀態,同時保持淺層?
是的,這是可能的,以下 git 命令是 shell 腳本函數,但實際上它們可能是 bat 文件或類似文件。
# clone
function git_shallow_clone() {
git clone --depth 1 --single-branch $@
}
# pull
function git_shallow_pull() {
git 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
s 指向 blob 的分支master
之外的標簽master
或至少單個分支感興趣感謝: https : //stackoverflow.com/a/7937916/432509 (對於這個答案的重要部分)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.