Search code examples
gitsvngit-rewrite-history

How to combine git history from wrong svn migration - old repository


We have a git repository migrated form SVN. Let's name it as WORKING. Due a svn copy folder operation the history was not well migrated. The error was :

SVN :  r1    \ --> common folder --> Project1 \ folder1
                                                file2 
  . 
  .  some time later
  .
  . 
SVN :  r1000 \ --> Common folder
               --> Project1 \ folder1
                              file2  
                    ^
                    |
                    ------> this folder has been migrated to GIT

This change caused a incomplete history migration (Only appear from HEAD to r1000) Now we want to add that old history into WORKING (from r1000 to r1), we have created a new git repository with the missing history (let's name as OLDEST) . The history log appear as :

WORKING --> A (1.2018) - B (2.2018) - C (3.2018) - D (HEAD)
OLDEST --> E (1.2016) ... F (1.2017) 

We want this log history

WORKING --> E ... F --> A - B - C 

The paths are exactly the same and we want keep the history when you see the full history of a file. The test i made i was unable to mix those histories, it is possible?

More details

I migrated the repository using :

URL=http://server.name/project1
git svn clone --authors-file=authors.txt $URL -r1000:HEAD first-migration 

Some time later I have done

URL=http://server.name/common/
git svn clone --authors-file=authors.txt $URL -r1:1000 second_migration
cd second_migration
git filter-branch 

Now we have two repositories. first-migration is in use and contains active development, second_migration contains the old revisions (from 1-1000)

Mi current solution is :

mkdir migration
cd migration
git init
git remote add newest ssh://gitserver:first-migration
git remote add older  ssh://gitserver:second-migration
git remote update 
git checkout newest/master -b new.master
git checkout 1abc2def3   -b new.firstcommit 
git checkout older/master -b old.master
git rebase --preserve-merges --root --committer-date-is-author-date new.master
git checkout new.master -b master
git remote add fullhistory ssh://gitserver:final.git
git push fullhistory --all 

In this case new.firstcommit is the first commit i made during first migration (r1000) (as reference for documentation)

After those operations the full history is available on remote repository but the history appear disconnected

enter image description here

My question is about how to integrat old history in the better way.


Solution

  • Thans to the comment of alo-malbarez here and this page i could solve the problem. Finally I did :

    git checkout old.master
    git cherry-pick new.firstcommit
    # I commit the day I merged histories. 
    git commit --allow-empty -m "Mixing histories"
    git rebase -s recursive -Xtheirs --onto old.master new.firstcommit new.master
    git push --all --tags
    

    And this solved my problem.