Tuesday, September 20, 2011

Merging two git repositories and keeping their history

To merge our repositories together we use the instructions given in [1].

<might be unnecessary>
First we create a new branch with
git branch newbranch
on MIRPCADB and switch to it using
git checkout newbranch 
and push it using
git push -u origin newbranch
</might be unnecessary>

Now we move over to our No.Noise repository and use the following command to fetch the contents of MIRPCADB in a new branch of No.Noise
git fetch git@github.com:tjom/MIRPCADB.git master:newbranch
To be able to use the commit history we use the following command to move the files from newbranch into a directory called old in our master branch
git filter-branch --index-filter \
    'git ls-files -s | \
        sed "s-\t-&'"old"'/-" | \
        GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && \
        mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE
    ' "newbranch"
followed by
git merge newbranch
Now we can simply move (copy and delete(!)) the files to our NoNoise plug-in src directory. After calling
git add -u
all files should be recognized as 'renamed', which means that their history will be preserved.

After committing and pushing the changes to the desired branch, we call
git branch -d newbranch
to remove the dummy branch.


[1] http://zrajm.org/ref/git-repo-merging.html

No comments:

Post a Comment