This happened to me when I did the migration from SVN to Git for third time in my career.
Once all the source from trunk and other branches was imported into Git repository, a few set of developers made hotfix changes in svn and pushed it up to the trunk.
I was then asked to import these selective commits into the git's master branch . Unfortunately, I couldn't import these changes straight away into my production git repository as the developers had already started working on it. I as a Git admin, had forked new branches and commits were pushed up the central repository.
I had to take a different approach and here it is:
1) At the time of Migration, I had a non bare repository where in I used to periodically pull commits from SVN. The repo was /home/mayur/Migration
2) My production git repository,/mnt/Platform.git was a bare repository that was born out of the non bare repository I spoke in point #1.
3) Now to import the latest changes in my git repository, I decided to
- First clone from my central repository
git clone mayur@gitServer:/mnt/Platform.git
- Now import the latest from svn into my non bare repository, /home/mayur/Migration and locked svn's trunk branch via hooks to block any more commits.
- Now, in the locally cloned repo, I added the origin of my non bare
repository,/home/mayur/Migration
4) Now I had to diff for commits between svn_master(which is the latest copy of trunk in svn that has hotfix changes) with the git's master branch and cherry-pick them selectively.
So I did,
I dumped all of these commits information into a file .
5) Then I had to cherry-pick the commits into the git's master branch but found a weird issue.
The authors were not correctly set in most of the commits and hence cherry pick failed complaining about it. All the committer names were missing and instead only email ids were observed.
So I had to amend the author name correctly via ,
git filter-branch -f --commit-filter 'if [ "$GIT_AUTHOR_NAME" = "<user1@abc.com>" ];then export GIT_AUTHOR_NAME="username surname"; export GIT_AUTHOR_EMAIL=username@abc.com;fi; git commit-tree "$@"'
6) Following this I checkout to master branch and cherry-picked the commits into it with
git cherry-pick <commit_sha>
Once all the source from trunk and other branches was imported into Git repository, a few set of developers made hotfix changes in svn and pushed it up to the trunk.
I was then asked to import these selective commits into the git's master branch . Unfortunately, I couldn't import these changes straight away into my production git repository as the developers had already started working on it. I as a Git admin, had forked new branches and commits were pushed up the central repository.
I had to take a different approach and here it is:
1) At the time of Migration, I had a non bare repository where in I used to periodically pull commits from SVN. The repo was /home/mayur/Migration
2) My production git repository,/mnt/Platform.git was a bare repository that was born out of the non bare repository I spoke in point #1.
3) Now to import the latest changes in my git repository, I decided to
- First clone from my central repository
git clone mayur@gitServer:/mnt/Platform.git
- Now import the latest from svn into my non bare repository, /home/mayur/Migration and locked svn's trunk branch via hooks to block any more commits.
- Now, in the locally cloned repo, I added the origin of my non bare
repository,/home/mayur/Migration
git remote add svn_origin /home/mayur/Migration
git fetch svn_origin
git checkout -b svn_master svn_origin/master
4) Now I had to diff for commits between svn_master(which is the latest copy of trunk in svn that has hotfix changes) with the git's master branch and cherry-pick them selectively.
So I did,
git log master..svn_master
shows everything that master needs to have everything svn_master has.I dumped all of these commits information into a file .
5) Then I had to cherry-pick the commits into the git's master branch but found a weird issue.
The authors were not correctly set in most of the commits and hence cherry pick failed complaining about it. All the committer names were missing and instead only email ids were observed.
So I had to amend the author name correctly via ,
git filter-branch -f --commit-filter 'if [ "$GIT_AUTHOR_NAME" = "<user1@abc.com>" ];then export GIT_AUTHOR_NAME="username surname"; export GIT_AUTHOR_EMAIL=username@abc.com;fi; git commit-tree "$@"'
6) Following this I checkout to master branch and cherry-picked the commits into it with
git cherry-pick <commit_sha>