-
Notifications
You must be signed in to change notification settings - Fork 15
Getting commits from SVN
To retrieve commits from the svn repository you'll need to run git s,vn rebase. This pulls in all commits from SVN tries shoves them before any local commits (any conflicts will have to be resolved). Rebasing will be covered briefly here.
-
Let's make some changes to SVN.
% svn update U README Updated to revision 9. % ls INSTALL README % echo "SVN Addition" >> INSTALL % svn status M INSTALL % svn commit -m "Adding another line to INSTALL" Sending INSTALL Transmitting file data . Committed revision 12. -
We'll verify that the commit hasn't made it into our git repo tracking SVN.
% git log commit 2d4404df0fad2827c86caf184d83593a6d5e27a6 Author: [email protected] <[email protected]@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Thu Sep 15 05:15:59 2011 +0000 Adding 'SVN Addition' to INSTALL git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk@11 ba991f9a- commit 66500b52d874100ad83f09bb720d19b0fbcacf0c Author: [email protected] <[email protected]@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Thu Sep 15 05:11:47 2011 +0000 Adding 'SVN Addition' to INSTALL git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk@10 ba991f9a- commit 72d8e8421e66a703256cf26b46d04e9ccdb401a3 Author: [email protected] <[email protected]@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Wed Sep 7 05:16:28 2011 +0000 Adding a line. git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk@9 ba991f9a-d ... -
Let's make some changes in the git repo tracking SVN.
% echo "Git Addition" >> INSTALL % git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: INSTALL # no changes added to commit (use "git add" and/or "git commit -a") % git add INSTALL % git commit -am "Adding a line to INSTALL through git." [master dfa390f] Adding a line to INSTALL through git. 1 files changed, 1 insertions(+), 0 deletions(-) % git log commit dfa390fcadfde029bbc37ccf6fb927c77cf2a2f1 Author: Abhik Pramanik <[email protected]> Date: Wed Sep 14 22:23:23 2011 -0700 Adding a line to INSTALL through git. commit 2d4404df0fad2827c86caf184d83593a6d5e27a6 Author: [email protected] <[email protected]@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Thu Sep 15 05:15:59 2011 +0000 Adding 'SVN Addition' to INSTALL git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk@11 ba991f9a- commit 66500b52d874100ad83f09bb720d19b0fbcacf0c Author: [email protected] <[email protected]@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Thu Sep 15 05:11:47 2011 +0000 Adding 'SVN Addition' to INSTALL git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk@10 ba991f9a- ... -
Let's pull the SVN changes into the git repo via
git svn rebase. What this does is replays your local commits onto that of the SVN HEAD. WTF? Here's an illustrated example:

Make sense? If you want to read more about rebasing it, I suggest reading this chapter in Progit. Rebasing keeps your commit log clean of merge commits. For now it's our only option if we want to make commiting back to SVN easy, so let's try it out:
```
% git svn rebase
M INSTALL
r12 = 03a360e771110927da699ba346acc53fd5c0f105 (refs/remotes/trunk)
First, rewinding head to replay your work on top of it...
Applying: Adding a line to INSTALL through git.
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging INSTALL
CONFLICT (content): Merge conflict in INSTALL
Failed to merge in the changes.
Patch failed at 0001 Adding a line to INSTALL through git.
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".
rebase refs/remotes/trunk: command returned error: 1
```
Notice an error occured when we replayed our local commit on top of the latest SVN commit log. We have the option of skipping (discards the commit), aborting (resets the local commit log), or resolving. Resolving the conflict is done like any other source control software (in this case we use vim to open and edit the conflicted file):
```
% vim INSTALL
% git rebase --continue
You must edit all merge conflicts and then
mark them as resolved using git add
% git add INSTALL
% git rebase --continue
Applying: Adding a line to INSTALL through git.
% git log
commit 0884bf74ff4ac6835a2bd8ab0c2ba13674aa9177
Author: Abhik Pramanik <[email protected]>
Date: Wed Sep 14 22:23:23 2011 -0700
Adding a line to INSTALL through git.
commit 03a360e771110927da699ba346acc53fd5c0f105
Author: [email protected] <[email protected]@ba991f9a-d5de-4771-8651-3090c57d9f48>
Date: Thu Sep 15 05:19:46 2011 +0000
Adding another line to INSTALL
git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk@12 ba991f9a-
commit 2d4404df0fad2827c86caf184d83593a6d5e27a6
Author: [email protected] <[email protected]@ba991f9a-d5de-4771-8651-3090c57d9f48>
Date: Thu Sep 15 05:15:59 2011 +0000
Adding 'SVN Addition' to INSTALL
git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk@11 ba991f9a-
commit 66500b52d874100ad83f09bb720d19b0fbcacf0c
Author: [email protected] <[email protected]@ba991f9a-d5de-4771-8651-3090c57d9f48>
Date: Thu Sep 15 05:11:47 2011 +0000
Adding 'SVN Addition' to INSTALL
git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk@10 ba991f9a-
```