Git: Push shallow clone to a new remote without 'unshallow'?

后端 未结 2 1727
孤独总比滥情好
孤独总比滥情好 2021-01-15 09:47

I made a shallow clone of a repository with git clone --depth=1. I made some changes... apparently without understanding the complications of shallow clones...

相关标签:
2条回答
  • 2021-01-15 10:17

    Why can't I push from a shallow clone? seems to have some additional commentary. In fact, look at this comment:

    Update 2015: with Git 2.5+, you will even be able to fetch a single commit. See "Pull a specific commit from a remote git repository"

    So perhaps you can't push, but from the other side, you can pull. Have you tried that?

    0 讨论(0)
  • 2021-01-15 10:29

    I would do it as follows:

    1. Create a new root branch:

      git checkout --orphan truncated_master
      
    2. Populate its initial commit with the earliest available commit in your shallow repository:

      START_COMMIT=$(git rev-list master|tail -n 1)
      git checkout $START_COMMIT -- .
      git commit -m "Initial commit"
      
    3. Copy all commits from master to the new branch:

      git cherry-pick $START_COMMIT..master
      
    4. Push the new branch to the new remote:

      git push origin truncated_master:master
      
    0 讨论(0)
提交回复
热议问题