Last updated by FatherShawn on Tue, 2011-09-06 18:25
Joshua Jabbour gave a great session on using the Git distributed version control system at Drupal Camp NYC 8. I was able to come home, download the source for Git, and easily build it on my laptop. I'd just started a new drupal project, and hadn't moved it into svn yet, so I easily created a git repostitory for the project. In fact, it was so easy I really wanted to move all my projects into git and chuck svn. That wasn't hard either, but I did need to combine two different tutorials and one of those used deprecated commands, so I thought I'd write up how I did it. This write up assumes a *nix environment. Hopefully someone who speaks Windows will add to the page if that is needed. References to the original sources are at the end.
- Before you begin, check your svn working copy and be sure all changes are committed to the svn repository.
- Extract the Authors from SVN: git tracks more information about authors than svn. We're going to use a shell script to parse the svn log and create a text file that lists all the authors shown in svn. You will then edit the text file to map those users to the names and email addresses that git needs.
- Depending on your editor, open a blank text file or create and edit a text file: extractAuthors
- Paste the following script into the text file:
#!/usr/bin/env bash
authors=$(svn log -q | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq)
for author in ${authors}; do
echo "${author} = NAME <USER@DOMAIN>";
done
- Save extractAuthors, naming it if necessary, into a directory in your shell path. I put mine in /usr/local/bin/
- Change the permissions on extractAuthors to make it executable.
- Change directory to your svn working copy.
- Execute the script: extractAuthors > /path/to/your_project-authors.txt
- Open your_project-authors.txt in an editor. Each author will be on a line such as:
luke = NAME <USER@DOMAIN>
darth = NAME <USER@DOMAIN>
leia = NAME <USER@DOMAIN>
Add real names and emails and save the file:
luke = Luke Skywalker <luke@tatooine.net>
darth = Darth Vader <lordvader@imperialpalace.org>
leia = Leia Organa <lorgana@imperialsenate.org> - Pull down your SVN into a temporary Git repository: We're going to move the project through git twice. The first time converts it and the second time cleans out extra SVN data you don't need anymore. For this write-up I'm using your_project as the directory that you are migrating from svn to git and projects as the parent directory for your_project. Here are the commands:
- cd projects
- mkdir svn_your_project
- cd svn_your_project
- git svn init http://example.com/your_project/ --no-metadata or git svn init file:///path/to/local-repo/your_project --no-metadata
- git config svn.authorsfile /path/to/your_project-authors.txt
- git svn fetch
- Backup your_project somewhere and delete the directory. We're going to restore it from the temporary git repository.
- cd projects
- mv your_project your_project.bak
- Create your clean working copy with git: Now we're going to clone the temporary git repository back into the same point in the file system where your project was originally.
- git clone svn_your_project your_project
- Now your_project is in git with all the revision history, you still have the original at your_project.bak in case something went wrong. You can delete it as soon as your sure that all went well:
- sudo rm -r svn_your_project
References:
Cleanly Migrate Your Subversion Repository To a GIT Repository
Creating a svn.authorsfile when migrating from subversion to git