Chapter 8. Git and Other Systems
1.??git svnallows you to use Git as a valid client toa Subversion server, so you can use all the local features of Git and then pushto a Subversion server as if you were using Subversion locally.
?
$ git svn clone http://progit-example.googlecode.com/svn/ -T trunk-b branches -t tags
This runs the equivalent of two commands—gitsvn init followed by git svn fetch?—on the URL you provide. The -T trunk -b branches -t tags?part tells Git that this Subversion repository followsthe basic branching and tagging conventions. If you name your trunk, branches,or tags differently, you can change these options. Because this is so common,you can replace this entire part with –s:
$ git svn clone file:///tmp/test-svn -s
$ git show-ref
1cbd4904d9982f386d87f88fcelc24ad7c0f0471 refs/heads/master
aeelecc263l8l64f355a883f5d99cffOc852d3c4 refs/remotes/my-calc-branch
03d09bOe2aad427e34a6d50ff147128e76cOeOf5 refs/remotes/tags/2.0.2
50d02ccOadc9da4319eeba0900430ba219b9c376 refs/remotes/tags/release-2.0.1
4caaa711a50c77879a91b8b90380060f672745cbrefs/remotes/tags/release-2.0.2
1c4cb508l44c513ffl214c3488abe66dcb929l6frefs/remotes/tags/release-2.0.2rcl
1cbd4904d9982f386d87f88fcelc24ad7c0f0471 refs/remotes/trunk
Tags are added as remote branches, not as real Git tags.
$ git log ?1
commit 938bla547c2cc92033b74d32030e86468294a5c8
Author: schacon <schacon@4c93b258-373f-11de-be05-5f7a86268029>
Date:?? Sat May 2 22:06:442009 +0000
?
??? Adding git-svninstructions to the README
?
??? git-svn-id:? file:///tmp/test-svn/trunk@79 4c93b258-373f-11de-be05-5f7a86268029
If you want to push to both a Git server and a Subversionserver, you have to push (dcommit) to the Subversion serverfirst, because that action changes your commit data.
$ git svn branch opera
$ git svn show-ignore >?.git/info/exclude
That way, you don't litter the project with .gitignorefiles. This is a good option if you're the only Git user on a Subversion team,and your teammates don't want .gitignore files in the project.
?
----- Migrating To Git -----
schacon = Scott Chacon <schacon@geemail.com>
selse = Someo Nelse <selse@geemail.com>
To get a list of the author names that SVN uses, you canrun this:
$ svn log --xml | grep author | sort -u | perl -pe? 's/.>(.?)<./$l = /'
And then you can import the SVN history to your git repo:
$ git-svn clone http://my-project.googlecode.com/svn/ ?--authors-file=users.txt --no-metadata -s my_project
--no-metadata tells Git not toinclude metadata that Subversion normally imports. Now not only does the Authorfield look a lot better( in a Git convention), but the git-svn-id is no longerthere, either.
?
$ cp -Rf .git/refs/remotes/tags/* .git/refs/tags/
$ rm -Rf .git/refs/remotes/tags
$ cp -Rf .git/refs/remotes/* .git/refs/heads/
$ rm -Rf .git/refs/remotes
$ git push origin --all
$ git clone git://git.kernel.org/pub/scm/git/git.git
$ cd git/contrib/fast-import
To set up your client, you must export the P4P0RT?environment variable to point to the Perforce depot:
$ export P4P0RT=public.perforce.com:l666
Run the git-p4 clone?command under fast-import folder to import the project from the Perforceserver: (You must have Python and the p4?tool installed on your machine for this import to work.)
$ git-p4 clone //public/jam/src@all /opt/p4import
If you go to the /opt/p4import directory and run gitlog, you can see the git-p4?identifier in each commit which tracks the Perforce depot path and changenumber. You can use git filter-branch to remove the identifier strings:
$ git filter-branch --msg-filter ' sed -e "/^\[git-p4:/d"'
commit refs/heads/master
mark :l
committer Scott Chacon <schacon@geemail.com> 1230883200 ?0700
data 29
imported from back_2009_01_02deleteall
M 644 inline file.rb
data 12
version two
commit refs/heads/master
mark :2
committer Scott Chacon <schacon@geemail.com> 1231056000 ?0700
data 29
imported from back_2009_01_04from :1
deleteall
M 644 inline file.rb
data 14
version three
M 644 inline new.rb
data 16
new version one
(...)
The format is like:
commit [branch]
mark: [mark]
commiter [author] [date]-[timezone]
data [commit-message-size]
[commit-message]
deleteall
M [file-mode] inline [file-path]
data [file-size]
[file contents]
…
mark is the fast-import?term for an identifier you give to a commit; as you create commits, you giveeach one a mark that you can use to link to it from other commits.
?
23.??Because many systems think oftheir revisions as changes from one commit to another, fast-import?can also take commands with each commit to specify whichfiles have been added, removed, or modified and what the new contents are. Youcould calculate the differences between snapshots and provide only this data,but doing so is more complex—you may as well give Git all the data and let itfigure it out. If this is better suited to your data, check the fast-import?man page for details about how to provide your data in thismanner.