I created a git repository and committed content to it.
git clone git://newrepo.com/project.git # Empty repository
tar -xzvf project-0.6.tar.gz -C project # Fill it with tar contents
cd project
git commit -a
... Do work
... Commit
... Push
But later found a recovered version of the same project with git history, made with an earlier version of the tar.gz.
How can I import the history from the old project into the new one?
I'm thinking I need to do something like this:
git clone git://newrepo.com/project.git # Start fresh
cp -r project project_backup # Backup the content
cd project
git init # Wipe everything
git remote set-url origin git://oldrepo.com/project.git # Point to the old project
git pull # Get clean history
cp -r ../project_backup . # Apply new content
git commit -a # One big commit
git remote set-url origin git://newrepo.com/project.git # Point to the new project
git push # Push changes
But I don't think git init works like that. man says it doesn't actually touch the git history. I heard git rebase might be the solution, but I'm not sure how to use it in this context.
In git-manpage format: I'd be turning this:
A---B---C master (oldrepo)
D---E---F master (newrepo)
into
A---B---C---D'---E'---F' master (newrepo)
Edit:
I do have push access to oldrepo. I'm sure I could figure out how to apply my changes to oldrepo, but then how would I replace newrepo with oldrepo?
Edit2
git rebase was suggested. I'm having problems with it. When I resolve the conflicts and finish with the rebase,
git clone git@newrepo.com/project.git project-rebase
cd project-rebase
git fetch --all
git remote add original https://oldrepo.com/project-old.git
git fetch original
git rebase --onto original/master 6210d0b3cf20f506ce0bab7849550b38c9effb15 master
--- resolving conflict ---
git rebase --continue
At this point I hoped we were done. The git log looks great, but:
$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 102 and 11 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean'
$ git push origin master
To newrepo.com:project.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@newrepo.com:project.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.