我正在尝试减少大型存储库的历史记录。我做了一个浅克隆
git clone --depth --no-single-branch 1000 url
Run Code Online (Sandbox Code Playgroud)
然后我用这个脚本检查了所有分支
#!/bin/bash
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
git branch --track ${branch#remotes/origin/} $branch
done
Run Code Online (Sandbox Code Playgroud)
在那之后,我改变了原点
git remote add new-origin new-url
git remote rm origin
git remote mv new-origin origin
Run Code Online (Sandbox Code Playgroud)
然后我推动了新的存储库。我的问题是系统不允许将浅克隆推送到新存储库。如果我返回我的旧存储库以取消浅显:
git fetch --unshallow
Run Code Online (Sandbox Code Playgroud)
然后整个回购再次同步。你知道有一种方法可以在没有 unshallow 的情况下对我的克隆进行 unshallow 吗?
谢谢
所以这就是你想要做的。继续克隆整个 repo,或者fetch --unshallow. 现在,假设您想要作为新存储库的根提交的提交的 SHA 是abc123. 请执行下列操作:
git checkout --orphan temp abc123
git commit -C abc123 #creates a root commit with the contents and commit message of abc123
git replace abc123 temp #"tricks" git into using the root commit instead of `abc123`
git filter-branch -- --all #rewrites the whole repo
git checkout master
git branch -D temp
Run Code Online (Sandbox Code Playgroud)
然后你可以推送到你的新远程仓库。