Search code examples
gitclonecommitrecover

how to recreate old commits that got missing and unreachable at repository move


I have moved from gitorious to gitlab and when doing the first push to gitlab, forgot to also push all my tags.

In the old repository, some commits were only reachable due to them having a tag at their commit chain tip. Since the new repo didn't get tags pushed, these commits are now unreachable -- in fact, they are not even present in my local or new remote repository anymore (probably gc'ed). I was hoping I could just somehow recover these commits without messing with any history. Here's the situation:

A---B---C---D---E---F <-- master today
     \                
      X---Y---Z       
              ^       
              lost tag

I still have the old local repository on my disk (linked with a now unavailable gitorious remote) together with the commits X Y Z which I'd like to push to the new repo.

How would I go about doing this?


Solution

  • I've managed to fix my problem according to nwinkler's suggestion:

    In my old local repo, I've changed the remote to the new repo and pushed all tags:

    git remote rm origin
    git remote add origin [new repo URL]
    git push --tags
    

    (I think I could've used set-url instead but I didn't know that from the top of my head.)

    Interestingly, this didn't push the "lost tag" even though it existed in the old local repo. I had to create a temporary branch on the locally existing tag and push it

    git checkout <lost-tag-which-exists-in-old-local>
    git checkout -b temp-resurrect
    git push -u origin temp-resurrect
    git branch -d temp-resurrect
    git push origin --delete temp-resurrect
    

    After this I could see the commits X Y Z and the tag in the new remote repository (web interface) and pull the tag and commits to the new local repo.

    I'll leave this question open for now, in case someone finds a better solution to the problem.