Git: retroactively introduce multiple merges

I am trying to learn git by applying it (retroactively) to a project where I tracked a remote codebase for a while. When I put everything in git, I just created a remote branch for all external versions and put my versions in master , so currently my repository looks like this:

 master: A0---A1.0--A1.1--A2.0--A2.1-.... \ remote: B1----------B2-----------.... 

My question is: how do I retroactively tell git about the merges that took place to make the repository look like (code should not change):

 master: A0---A1.0--A1.1--A2.0--A2.1-.... \ / / remote: B1----------B2-----------.... 

Standard git disclaimer: no published story will be affected by the above steps :)

EDIT: The following is how I did it using the vaccinations suggested by Kevin:

First, I manually created .git / info / grafts as follows (all entries are sha1):

 A1.0 A0 B1 A2.0 A1.1 B2 

Then, checking that everything looks good (gitx), I ran git filter-branch with no arguments.

Filter-branch will make the transplants permanent and keep the refs in the original, fixed in refs/originals/... so that you can return via git reset --hard refs/originals/refs/heads/master . Since everything looked good, I removed all the leftovers as follows:

 rm .git/info/grafts rm .git/refs/originals 

If you have garbage collected, you need to do git update-ref -d refs/originals/refs/heads/master .

+4
source share
3 answers

It looks like you want transplants . You can create grafts for new desires (do not forget to include the original parent in the transplant!), And when everything looks good, use git filter-branch (read the manpage!) To bake it in stone.

+3
source

You can completely fake this by doing an interactive reboot, indicating that you want to edit all these commits, and fix them merging:

 git rebase -i A0 master # change the lines for A1.0 and A2.0 to "edit" # git stops at A1.0 git merge --no-commit --strategy=ours B1 # the SHA1 of B1, of course git commit --amend git rebase --continue # git stops at A2.0 git merge --no-commit --strategy=ours B2 git commit --amend git rebase --continue 

Every time you stop, you are technically teamed up, but with our strategy, which saves all the contents of your current commit. --no-commit tells git to stop before writing. Then you change the current commit (which basically means replacing) to merge, instead of merging a separate commit, as usual. TA-dah! A1.0 has been replaced with a new latch with an identical tree, but an additional parent. commit --amend gives you the ability to edit the message; You can do this to leave some notes about what you have done.

+2
source

I know this is an old question, but there is an updated way to accomplish this (with Git 1.6.5).

 git replace --graft <commit> <parent1> <parent2> 

Where <> are SHA hashes

+1
source

All Articles