Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unshallow a clone without unshallow?

Tags:

git

I'm trying to reduce the history a la large repository. I made a shallow clone

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

Then I checked all branches with this script

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

After that, I've changed the origin

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

And then I made a push on the new repository. My problem is that system does not permit to push to a new repository a shallow clone. If I return to my old repository to unshallow with:

git fetch --unshallow

then the whole repo is synced again. Do you know a way to unshallow my clone without unshallow?

Thanks

like image 681
Killrazor Avatar asked Feb 19 '16 16:02

Killrazor


1 Answers

So here is what you want to do. Go ahead and clone the whole repo, or fetch --unshallow. Now, let's say the SHA of the commit you want as the root commit of your new repo is abc123. Do the following:

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

Then you can push to your new remote repo.

like image 121
David Deutsch Avatar answered Oct 04 '22 15:10

David Deutsch