Table of contents
Initialize local Git - SVN repo
Lets say we want to test and work with Tiki branch "users" first. Make new dir called users and cd into it:
mkdir users; cd users
Now we git svn init
the branch we want (the users branch) in the current dir with specified SF.net username:
[luci@vm5163 users]$ git svn init https://svn.code.sf.net/p/tikiwiki/code/ . --username=luciash --branches=users
Fetch all from SVN
Prepare lot of time and patience for this command, really:
[luci@vm5163 users]$ git svn fetch --no-follow-parent
This will take so loooooong time usually as it needs to map all the commits history to our local Git repo! Be patient or give up here! ;)
Getting list of local Git branches created
[luci@vm5163 users]$ git branch -r
Editing and commiting to local Git repo
Edit a test file:
[luci@vm5163 users]$ vim test.txt
Lets put there something:
This change was commited using the follwoing git svn command: git svn dcommit
[luci@vm5163 users]$ git commit -m "Test for git svn dcommit" . [detached HEAD 8133175] Test for git svn dcommit Author: luciash <luci@...i.org> Committer: luci <luci@...s.net> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly: git config --global user.name "Your Name" git config --global user.email you@example.com If the identity used for this commit is wrong, you can fix it with: git commit --amend --author='Your Name <you@example.com>' 1 files changed, 1 insertions(+), 0 deletions(-)
OK, lets amend that: luci@vm5163 users$ git commit
amend author='luciash <luci@...i.org>'
In case you want to avoid the "configured automatically based on your username and hostname" message, do as they say:
[luci@vm5163 users]$ git config --global user.name "luciash d' being" [luci@vm5163 users]$ git config --global user.email g...@...h.cz
Just check the status
[luci@vm5163 users]$ git status # Not currently on any branch. nothing to commit (working directory clean)
All looks clean. Just ignore the "Not currently on any branch" message. We are in fact still on the "luci" branch (more on switching branches later below).
To make sure there were no changes on the remote SVN in the meantime we made our local commits:
{CODE()}
luci@vm5163 users$ git svn rebase --username=luciash
Current branch HEAD is up to date.
Using Git SVN dcommit
Now if we want to get our local changes we just made in Git to the central SVN repo, we need to use the git svn dcommit
command:
[luci@vm5163 users]$ git svn dcommit --username=luciash Committing to https://svn.code.sf.net/p/tikiwiki/code/users/luci ... Authentication realm: <https://svn.code.sf.net:443> SourceForge User Password for 'luciash': M test.txt Committed r59772 M test.txt r59772 = bfb561315c58b3f7d015acbaf43b6536acee2aec (refs/remotes/luci) No changes between current HEAD and refs/remotes/luci Resetting to the latest refs/remotes/luci
[luci@vm5163 users]$ git svn rebase Current branch HEAD is up to date.
Further examples
Fix something and commit that to SVN
Ah, there was a typo! Lets fix the typo:
[luci@vm5163 users]$ vim test.txt
See the diff:
[luci@vm5163 users]$ git diff diff --git a/test.txt b/test.txt index 0210543..dd98952 100644 --- a/test.txt +++ b/test.txt @@ -1 +1 @@ -This change was commited using the follwoing git svn command: git svn dcommit +This change was commited using the following git svn command: git svn dcommit
Looks good, lets commit that to our local Git repo:
[luci@vm5163 users]$ git commit -m "[FIX] typo" . [detached HEAD 91e929a] [FIX] typo 1 files changed, 1 insertions(+), 1 deletions(-)
Then commit it to the central SVN repo using git svn dcommit
:
[luci@vm5163 users]$ git svn dcommit --username=luciash Committing to https://svn.code.sf.net/p/tikiwiki/code/users/luci ... Authentication realm: <https://svn.code.sf.net:443> SourceForge User Password for 'luciash': M test.txt Committed r60458 RA layer request failed: OPTIONS of 'https://svn.code.sf.net/p/tikiwiki/code': Could not resolve hostname `svn.code.sf.net': Temporary failure in name resolution (https://svn.code.sf.net) at /usr/libexec/git-core/git-svn line 2295
(the "RA layer request failed" error message seems safe to be ignored - temporary glitch?)
Then git svn rebase
to make sure we are in "sync":
[luci@vm5163 users]$ git svn rebase M test.txt r60458 = 9f6a06bb109e68593a612d46a515583d3798bd73 (refs/remotes/luci) First, rewinding head to replay your work on top of it... Nothing to do.
Re-running the same command again will now say:
[luci@vm5163 users]$ git svn rebase Current branch HEAD is up to date.
Switching branches
Checkout another local Git branch:
[luci@vm5163 users]$ git checkout cartograf Previous HEAD position was 9f6a06b... [FIX] typo HEAD is now at bd71231... Rename branch folder names to simplify
Rebase to get the latest changes from SVN into that branch:
[luci@vm5163 users]$ git svn rebase M cartograf_tiki15/themes/CartoGraf/css/CartoGraf.css r60128 = 508aa68ea5a221759e9b895adb82689a00e0f4cc (refs/remotes/cartograf) M cartograf_tiki15/themes/CartoGraf/css/CartoGraf.css r60129 = bf4781123b7de3c3c693547ff77402f86c9e2853 (refs/remotes/cartograf) M cartograf_tiki15/themes/CartoGraf/css/CartoGraf.css r60134 = bfe082cb8d2aeb039015a3607cdb74f7762aa554 (refs/remotes/cartograf) M cartograf_tiki15/themes/CartoGraf/css/CartoGraf.css r60383 = 6aa56731659088974ecd5f0e7535f2db7174f98d (refs/remotes/cartograf) First, rewinding head to replay your work on top of it... Fast-forwarded HEAD to refs/remotes/cartograf.
Switch local branch back to luci:
[luci@vm5163 users]$ git checkout luci Previous HEAD position was 6aa5673... [FIX] paragraphs and uls on wiki pages were hidden HEAD is now at 9f6a06b... [FIX] typo
Fetching other branches, like 16.x
Fetching all branches would take ages, so lets try just with 16.x:
mkdir branches; mkdir branches/16.x; cd branches/16.x
[luci@vm5163 16.x]$ git svn init https://svn.code.sf.net/p/tikiwiki/code/branches . --branches=16.x Initialized empty Git repository in /home/luci/Devel/Tiki/branches/16.x/.git/ [luci@vm5163 16.x]$ git svn fetch --no-follow-parent W: Ignoring error from SVN, path probably does not exist: (160013): Filesystem has no item: File not found: revision 100, path '/branches/16.x' W: Do not be alarmed at the above message git-svn is just searching aggressively for old history. This may take a while on large repositories Checked through r9000
The last line "Checked through r..." changes dynamically. Now pray it does not fail and wait for it... ;)
Don't panic if it looks like it does nothing but checking. It will start to match things around revision r59800 or so and output it on your terminal then.
It should finally end up with something like this:
Checked out HEAD: https://svn.code.sf.net/p/tikiwiki/code/branches/16.x/lib r60476
Resources
There are some resources but all of them are a bit outdated:
- https://maymay.net/blog/2009/02/24/how-to-use-git-svn-as-the-only-subversion-client-youll-need/
- https://www.viget.com/articles/effectively-using-git-with-subversion (from 2008)
- http://flavio.castelli.name/2007/09/04/howto_use_git_with_svn/