Pushing to github after a shallow clone

前端 未结 5 915
春和景丽
春和景丽 2020-12-02 23:56

I had a massive git repo because of a huge number of commits, so following advice here I created a shallow clone. I\'ve made changes to this new local repo, and now I want t

5条回答
  •  自闭症患者
    2020-12-03 00:11

    I had a similar problem with pushing shallow clone repo to Bitbucket servers and I didn't have an access to old history. Finally, I had found a solution. See a sample script with comments below:

    #!/bin/bash
    
    # Fix shallowness
    mv .git/shallow .git/info/grafts
    
    git checkout --orphan temp # create temp empty commit
    git reset --hard
    git commit -m "Init" --allow-empty
    
    # Replace all shallow commits ids with new commit id. I copy-paste all refs from shallow file 
    git replace 196cdbdb30e608aae2fd7cbe97cc8c0e6fa66c06 
    git replace 4c645849b296aaafc1809a9e1537c0fb305167ad 
    git replace 50eab8bd8c416c47354331211b1efd8688ad8e97 
    git replace 649dc7577b87d1b05dff05bf9adc5e46f6612dfa 
    git replace 6902148fde7b98ff0d6b6c6ebe929590322c95ff 
    git remote set-url origin http://:@ # reference to a remote repo to push
    git push origin 'refs/replace/*' # push replace refs to remote repo first
    git push -u origin master # push to master, finally
    
    # Clear some garbage just in case
    git filter-branch --tag-name-filter cat -- --all # rewrite history
    git push --force origin
    git fsck # check that everything is ok
    

提交回复
热议问题