在某些情况下,存储整个 git 历史记录(例如构建机器人)没有用。
是否可以对 git 存储库(master例如,具有单个分支)进行浅层克隆,并使其保持最新状态,同时保持浅层?
是的,这是可能的,以下 git 命令是 shell 脚本函数,但实际上它们可能是 bat 文件或类似文件。
# clone
function git_shallow_clone() {
git clone --depth 1 --single-branch $@
}
Run Code Online (Sandbox Code Playgroud)
# 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
}
Run Code Online (Sandbox Code Playgroud)
# 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
}
Run Code Online (Sandbox Code Playgroud)
# load history into a shallow clone.
function git_shallow_unmake() {
git fetch --no-tags --unshallow
}
Run Code Online (Sandbox Code Playgroud)
--no-tags使用很重要,否则您可能会克隆具有sha1指向分支外 blob 的 s 的标签mastermaster或至少一个分支感兴趣感谢:https : //stackoverflow.com/a/7937916/432509(对于这个答案的重要部分)
| 归档时间: |
|
| 查看次数: |
778 次 |
| 最近记录: |