git - 如何在没有 unshallow 的情况下取消克隆?

标签 git

我正在尝试减少大型存储库的历史记录。我做了一个浅克隆

git clone --depth --no-single-branch 1000 url

然后我用这个脚本检查了所有分支

#!/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

在那之后,我改变了原点

git remote add new-origin new-url
git remote rm origin
git remote mv new-origin origin

然后我在新存储库上进行了推送。我的问题是系统不允许将浅克隆推送到新存储库。如果我返回到我的旧存储库以取消浅化:

git fetch --unshallow

然后整个仓库再次同步。你知道一种不用 unshallow 来 unshallow 我的克隆的方法吗?

谢谢

最佳答案

这就是你想要做的。继续并克隆整个存储库,或 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

然后您可以推送到新的远程仓库。

关于git - 如何在没有 unshallow 的情况下取消克隆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35509581/

相关文章:

git - 计算每个时期的 Git 提交

git - Jenkins : stderr: Permission denied (publickey). fatal: 远端意外挂断

git - 为什么GitHub建议 "prefix your version names with the letter v?"

git - git是否存储文件的读、写、执行权限?

git - 使用远程 git 存储库的本地 Netbeans 设置

git - 当 Git diff 显示模式更改时,这意味着什么?

git - 排队时如何使用自托管代理清理构建

git - 重构为多个文件时如何保留 git 历史记录

windows - git clone 成功,但是 checkout 失败;由于文件夹有前导或尾随空格

git - 为每个分支保留不同的配置文件(未跟踪)