blueFast
blueFast

Reputation: 44381

Convert shallow repo to normal repo

I have "shallowed" a repo:

FIRST_COMMIT="bf450342272a94117d78eae34a140a2a39359dad"
git rev-parse ${FIRST_COMMIT} > .git/shallow
git fsck --unreachable
git gc --prune=now

Now I try to push:

! [remote rejected] develop -> develop (shallow update not allowed)

I understand that this limitation is due to the repo being shallow.

How can I convert a shallow repo to a normal repo?

I do not care about losing old history. Actually, I want to lose old history

To clarify this:

EDIT

Simply removing the .git/shallow file does not work:

» git push -f --set-upstream myorigin develop
error: Could not read d18d4a247bebd32a3b57b2c0e5f9c28749083211
fatal: revision walk setup failed
error: remote unpack failed: eof before pack header was fully read
error: failed to push some refs to 'git@somehost:repos/somerepo.git'

EDIT2

Trying to unshallow with fetch:

git fetch --unshallow

Still leaves a grafted repo:

commit bf450342272a94117d78eae34a140a2a39359dad (grafted)
Author: The author
Date:   Thu Nov 29 16:55:05 2018 +0100

    Chages by pre-commit hook (!?)

Upvotes: 8

Views: 2726

Answers (2)

Hugo
Hugo

Reputation: 29344

From "How to convert a Git shallow clone to a full clone":

The below command (git version 1.8.3) will convert the shallow clone to regular one:

git fetch --unshallow

Then, to get access to all the branches on origin (thanks @Peter in the comments)

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin

Upvotes: 10

blueFast
blueFast

Reputation: 44381

There is already a similar (identical?) question, with a very good answer which also solves my problem.

Basically I need to do the following:

git rev-parse --verify bf450342272a94117d78eae34a140a2a39359dad > .git/info/grafts
git filter-branch -f -- --all 

This will rewrite the history with the specified commit as the new root. Commit metadata will not be affected (date, owner, ...), just the commit hash, and the links between commits, so that the new graph starts from the specified root.

The repo will be then unshallowed / ungrafted, and can be normally pushed to new remotes, with reduced history.

Upvotes: 2

Related Questions