Create a git repository of a svn source tree using git-svn
Par haypo, mercredi 5 novembre 2008 à 13:09 :: Programmation :: #172 :: rss
When you're not allowed to commit in a svn repository, it's sometimes difficult to write an huge patch or to maintain an old patch. If the svn is updated while you're working on your patch (or after you wrote your patch), it will be difficult to update your patch. The main problem is that a patch has no reference to the revision number of the patched files. Your patch may apply to svn rev 67001 but not on svn trunk (rev 67103).
That's why I want to try git to be able to easily update a patch to the svn trunk. This article is a quick tutorial to setup your local git repository using git-svn.
To install git-svn on Debian/Ubuntu, use "apt-get install git-core git-svn".
Create the local git-svn repository
Create the repository:
$ git svn init https://svn.perl.org/parrot/trunk python-trunk $ cd python-trunk $ ls -l .git
The repository is empty. You have to download the full svn history (git svn fetch --all) or just one revision (which is faster). Since Python history is old (more than 60,000 revisions), I prefer to just get the last reversion:
$ git svn fetch -r67000 (...) A Lib/test/test_threadsignals.py A Lib/test/test_gc.py A Lib/test/test_codecmaps_kr.py A Lib/test/test_pyclbr.py A Lib/test/test_print.py (...) r67000 = f444d8e3d3b82002d8f4d3c3ee46eef18fc99f8d (git-svn) (...) $ git log|cat commit f444d8e3d3b82002d8f4d3c3ee46eef18fc99f8d Author: benjamin.peterson <benjamin.peterson@6015fed2-1504-0410-9fe1-9d1591cc4771> Date: Wed Oct 22 21:16:34 2008 +0000 fix #4150: pdb's up command didn't work for generators in post-mortem git-svn-id: http://svn.python.org/projects/python/trunk@67000 6015fed2-1504-0410-9fe1-9d1591cc4771 $ ls -F -1 configure* Lib/ Modules/ Objects/ (...)
Ok, we have a local copy of the the svn revision 67000. Git generated the commit number f444d8e3d3b82002d8f4d3c3ee46eef18fc99f8d for this revision.
Create your branch
I prefer to create a new branch for each test/patch set. The initial branch is called "master". Command to create a "bugfix" branch:
$ git checkout -b bugfix Switched to a new branch "bugfix"
So we are directly in the new branch. Let's play in this branch:
$ ./configure (...) $ git status # On branch bugfix # Untracked files: # (use "git add <file>..." to include in what will be committed) # # Makefile # (..) # Modules/python.o # (...) # config.status
Oh, we have to ignore the files generated by the compilation in our repository. But I prefer to do it in the master branch.
First commit
Ignore generated files in the master branch:
$ git checkout master Switched to branch "master" $ cat >.gitignore <<EOF # Files generated by the autotools config.status pyconfig.h (...) # Build files build *.o # Files generated by Python *.pyc EOF $ git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # .gitignore nothing added to commit but untracked files present (use "git add" to track)
Ok, the status is now clean but the file .gitignore is not part of our repository. Let's do our first commit!
$ git add .gitignore $ git commit [in your favorite editor] Create .gitignore: ignore generated files # Please enter the commit message for your changes. # (Comment lines starting with '#' will not be included) # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: .gitignore [save the file] Created commit 9b3cd1e: Create .gitignore: ignore generated files 1 files changed, 22 insertions(+), 0 deletions(-) create mode 100644 .gitignore $ git log|cat commit 9b3cd1e7ea620e65a71f4595e7fb1303addb7da3 Author: Victor Stinner <victor.stinner AT haypocalc.com> Date: Wed Nov 5 12:46:43 2008 +0100 Create .gitignore: ignore generated files commit f444d8e3d3b82002d8f4d3c3ee46eef18fc99f8d Author: benjamin.peterson <benjamin.peterson@6015fed2-1504-0410-9fe1-9d1591cc4771> Date: Wed Oct 22 21:16:34 2008 +0000 fix #4150: pdb's up command didn't work for generators in post-mortem git-svn-id: http://svn.python.org/projects/python/trunk@67000 6015fed2-1504-0410-9fe1-9d1591cc4771
The file is now part of the master branch.
Merge two branches
The commit was done in the master branch, but bugfix branch is unchanged. Commands to merge the bugfix branch with the master branch:
$ git checkout bugfix Switched to branch "bugfix" $ git merge master Updating f444d8e..9b3cd1e Fast forward .gitignore | 22 ++ 1 files changed, 22 insertions(+), 0 deletions(-) create mode 100644 .gitignore $ git log|cat commit 9b3cd1e7ea620e65a71f4595e7fb1303addb7da3 Author: Victor Stinner <victor.stinner AT haypocalc.com> Date: Wed Nov 5 12:46:43 2008 +0100 Create .gitignore: ignore generated files commit f444d8e3d3b82002d8f4d3c3ee46eef18fc99f8d Author: benjamin.peterson <benjamin.peterson@6015fed2-1504-0410-9fe1-9d1591cc4771> Date: Wed Oct 22 21:16:34 2008 +0000 fix #4150: pdb's up command didn't work for generators in post-mortem git-svn-id: http://svn.python.org/projects/python/trunk@67000 6015fed2-1504-0410-9fe1-9d1591cc4771
"git merge master", that's all! No confirmation is asked. You can see in the log that the commit number is the same of the commit in master branch. So it's not a new commit but just a reference to the master commit.
That's all
This tutorial is short but it's enough to setup a repository. Now you can play with all git commands and the GUIs (gitk, git gui)!
To get more informations about git-svn, read this article: An introduction to git-svn for Subversion/SVK users and deserters.
Commentaires
1. Le mercredi 5 novembre 2008 à 14:09, par Dedalus
2. Le mercredi 5 novembre 2008 à 14:25, par haypo
3. Le mercredi 3 décembre 2008 à 01:25, par Merwok
4. Le mardi 17 novembre 2009 à 16:19, par haypo
5. Le mardi 12 octobre 2010 à 10:40, par gucci outlet online
6. Le mardi 12 avril 2011 à 04:37, par AndyFletcherg
7. Le jeudi 29 septembre 2011 à 21:02, par легкие металлоконÑтрукции
8. Le lundi 14 novembre 2011 à 19:05, par Зеркальные фотоаппараты nikon
Ajouter un commentaire
Les commentaires pour ce billet sont fermés.