7

I have an old Git repo, call it app. Then, after a year, I wanted to rebuild the app from scratch, so I made a new repo, call it app-2.

Now, I realize I should've just made a new branch or something, instead of a new repo, because I want to move the history of app-2 on top of app and then get rid of app-2 so that app now has all the history of app + app-2.

Is this possible to do?

UPDATE:

I tried "reseting" the app repo by removing all the files in app (except for the .git directory) and making a commit. Then:

cd ~/Projects/app-2
git format-patch --stdout --root master > ../app/app-2-patches.txt
cd ../app
git am app-2-patches.txt

But, I got conflicts in places where I had branches in app-2.

Is it possible to apply the commits from app-2 while keeping the branch structure of the history of app-2?

ma11hew28
  • 121,420
  • 116
  • 450
  • 651
  • Is there a reason you need them to be in the same repo? And if so, is there a reason they have to be in the same branch? Why not just have a separate branch to store the history of the old version, and then just make your current new app be the master branch as-is? – Amber Apr 27 '12 at 17:17

2 Answers2

1

You can use git's graft points for this. First pull the history of app into app-2 from a remote, then follow the instructions e.g. in this answer.

Community
  • 1
  • 1
Benjamin Bannier
  • 55,163
  • 11
  • 60
  • 80
  • Specifically: You can use `git filter-branch` to turn a grafted history into "real" history, then get rid of the graft point. Keep in mind that this will change all your commit ids! –  Apr 27 '12 at 18:04
0

Step one is get the two apps in one repo; step two is merge them in some sensible way.

For step one I'd say push all of the repository branches in app-2 to branches in the app repository:

$ cd /path/to/app-2
$ git remote add app-repo /path/to/app
$ git push app-repo master:app-2-master     # master in app-2 goes to app-2-master in app repo
# repeat for other branches in app-2

Now over in the app repository you have all its branches and all the app-2 branches. Let's say you (want to) consider app-2 as derived from app. Then you rebase all of app-2 on app with:

$ cd /path/to/app
$ git checkout app-2-master
$ git rebase master

this might involve lots of work to resolve conflicts but git will be doing loads of work for you too.

GoZoner
  • 67,920
  • 20
  • 95
  • 145