How to properly push one git repository over another on codebasehq?
Asked Answered
F

1

1

I need to know the proper way to move git history from one repository to another on codebasehq.com. Situation:

  • there is a repo on codebasehq.com which I call "old" on path like mycompany.codebasehq.com/projects/OLDNAME/repositories/PROJECTNAME
  • after some development in old repo the team realized that this repo should actually be in different location on codebasehq.com and did "new" repo with just files from "old" repo and push it to mycompany.codebasehq.com/projects/NEWNAME/repositories/PROJECTNAME. So new repo right now has only one (initial) commit with all files from old repo but no old history at all.

I want to bring back history from old repo to new repo. I've read about rebase and graft here: How to rebase one Git repository onto another one? and I was able to successfully graft two repositories into one.

What I need to know is how to replace this new repo with 1 initial commit by rebased/grafted repo with all old history included. Should I delete this wrong new repo and re-create it from scratch or just push with some special flags to it?

UPD: I've tried to just push branch with full history (old+new) to mycompany.codebasehq.com/projects/NEWNAME/repositories/PROJECTNAME as new branch named fullhistory but got error:

bash-3.2$ git push codebasehq fullhistory
Counting objects: 104, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (74/74), done.
Writing objects: 100% (74/74), 1.74 MiB, done.
Total 74 (delta 36), reused 5 (delta 0)
fatal: unresolved deltas left after unpacking
error: unpack failed: unpack-objects abnormal exit
To [email protected]:mycompany/project/repo.git
 ! [remote rejected] fullhistory -> fullhistory (n/a (unpacker error))
error: failed to push some refs to '[email protected]:mycompany/project/repo.git'
Fluoroscope answered 19/11, 2012 at 8:36 Comment(2)
Unpacker error? Sounds like you don't have write access to the repository files.Therefrom
I suspect that's because fullhistory branch does not have common revisions with existing master in new repo, because I can successfully push the same branch to old repo where it originates from.Fluoroscope
T
1

You could try the following:

  • git clone OLDREPO
  • git remote add new NEWREPO
  • git fetch new

Your old history should now be in master while your new history is in new/master

  • git checkout new/master
  • git rebase -i master

This will start an interactive rebase that transplants everything from new/master onto master. Since you probably want to drop the first commit from your new code (the one that was a simple copy of the work at that time) you should delete the according line in the editor that will be shown to you. The rest should be set to pick.

Therefrom answered 19/11, 2012 at 15:14 Comment(3)
Thank you, although this is not what I'm looking for. My problem is in push actually.Fluoroscope
You can't push your merged history ontop of the old one as all newer SHA1 ids depend on the previous ones. Rewriting the old history (removing one commit and inserting the entire history) will irrevocably change all SHA1's in your repo. You have no choice but to delete everything in the repo and then push fullhistory. I recommend you to clone the new repo somewhere safe first. So in case something goes wrong, you can simply delete it and push the old state again.Therefrom
Make sure to tell your collegues though. Their local repositories will probably be quite confused :-). The safest thing would be for them to push all their changes into topic branches and you rebasing all of them. Afterwards they can delete their repos, do a fresh clone and check out their topic branches again.Therefrom

© 2022 - 2024 — McMap. All rights reserved.