Reduce Depth of an Existing Git Repo 让 git 只保留最近 n 次的 commit 删除其余的

shallow clone

git clone --depth=1 https://github.com/cloudwu/skynet.git
git log --oneline | wc -l
       1
du -hs .git
792K	.git

fully clone, and reduce the depth

git clone https://github.com/cloudwu/skynet.git
git log --oneline | wc -l
    2137                                       # 2137 entries!
du -hs .git
4.9M	.git

git fetch --depth 1  # this will fetch the newest commit from origin (if there are any) and then cut off the local history to depth of 1 (if it was longer)

git reflog expire --expire=all --all  # clear the reflog
git tag -l | xargs git tag -d            # remove all tags
git branch -d branchname             # remove a branch
git stash drop                               # drop the stashes

git gc --prune=all                        # remove the dangling commits
git log --oneline | wc -l
       1
du -hs .git
792K	.git

to undo a --depth and get the entire history again

git fetch --unshallow

Reduce Depth of an Existing Git Repo ⚓️
How to reduce the depth of an existing git clone?


EOF

posted on 2023-01-11 15:49  明天有风吹  阅读(118)  评论(0编辑  收藏  举报

导航

+V atob('d2h5X251bGw=')

请备注:from博客园