Project

General

Profile

RedmineGitTracking » History » Version 5

John Goerzen, 2008-03-07 23:50

1 1 John Goerzen
h1. Using Git to contribute to Redmine
2
3
Redmine's source tree is stored in Subversion, and everything eventually feeds into there.  Some who are comfortable using Git prefer to use it for its branching and merging features, and because you don't need to have SVN commit access to make commits.
4
5 3 John Goerzen
If you were looking for Subversion instructions, there are on the [[Download|download page]].
6
7 1 John Goerzen
h1. Initialization
8
9 3 John Goerzen
If you don't yet have Git, see the 5-minute Git Guide in the links below for download information.  You'll want a Git version of at least 1.5.x.
10
11 1 John Goerzen
To start out, run these commands:
12
13
<pre>
14
git clone git://git.complete.org/branches/redmine-integration
15
cd redmine-integration
16
git config --add remote.origin.fetch +refs/remotes/svn/*:refs/remotes/svn/*
17
git fetch
18
</pre>
19
20
h2. Exploration
21
22
You can see all the branches that Git obtained for you:
23
24
<pre>
25
git branch -r | less
26
</pre>
27
28
You'll see output like this.  (Many lines omitted here)
29
30 2 John Goerzen
<pre>
31 1 John Goerzen
  origin/HEAD
32
  origin/fb-bug-259-git
33
  origin/fb-bug-261-issue-redirect
34
  origin/fb-bug-641-context-done
35
  svn/git
36
  svn/issue_relations
37
  svn/mailing_lists
38
  svn/tags/0.6.3
39
  svn/tags/0.6.3@1011
40
  svn/time
41
  svn/trunk
42
  svn/wiki
43 2 John Goerzen
</pre>
44 1 John Goerzen
45
The "origin" branches are being maintained in Git (no corresponding Subversion branch).  The svn branches are identical copies of the same branch in the Redmine Subversion repository.
46
47
You'll base your work off these branches.
48
49
h1. Starting Your Feature
50 2 John Goerzen
51
With git, branches are cheap and merges are easy, so you'll usually want to start a new branch for each feature you work on.  A single branch will probably correspond to a single issue in Redmine when you submit the patch.
52
53
You'll want to base your patch on svn trunk.  So you'll set up a branch like so:
54
55
<pre>
56
$ git branch my-feature svn/trunk
57
Branch my-feature set up to track remote branch refs/remotes/svn/trunk.
58
$ git checkout my-feature
59
</pre>
60
61
The first line created a branch named @my-feature@, which will be based on svn/trunk.  The second command checks out that branch, which means that your working copy is switched to it, and any commits you make will be posted to that branch.
62
63
Note that the act of committing doesn't sent any patches to anyone else; as Git is distributed, commits are recorded locally only until you're ready to push them upstream.
64
65
You can run @git branch@ to see what branch you're on -- it'll have an asterisk next to it, like this:
66
67
<pre>
68
$ git branch
69
  master
70
* my-feature
71
</pre>
72
73
h1. Working on your feature
74 3 John Goerzen
75
Now that you have made your branch, it's time start work.
76
77
Here are some commands you may want to use:
78
79
|_.task|_.command|
80
|Commit outstanding changes|@git commit -a@|
81
|Add a new file to the repo|@git add filename@|
82
|Remove a file from the repo and working directory|@git rm filename@|
83
|Rename a file in repo and working directory|@git mv oldname newname@|
84
|View history|@git log@|
85
|Get help|@git commandname --help@|
86
87
Note that @git command@ is the same as @git-command@.  You can use @man git-command@ to see the manpage for any Git command.
88 4 John Goerzen
89
h1. Merging with trunk
90
91
If you are working with your feature for awhile, you may find that Subversion has updated.  Ideally you will make your eventual diff work with the latest trunk revision, so you'll want to make your patch work with that.  To update your patches to apply on top of the latest trunk, do this:
92
93
<code>
94
git fetch
95
git rebase svn/trunk
96
</code>
97
98 5 John Goerzen
99 4 John Goerzen
h1. Submitting your Patch
100
101
When you're done working on your patch, make sure you have committed it to Git.  Then you can generate diffs.  
102
103
You can generate one big diff, that includes all the changes you have made on the branch, even if they were made in multiple commits.  Run this:
104
105
<code>
106
git diff svn/trunk..HEAD > /tmp/feature.diff
107
</code>
108
109
That means "calculate the difference between the trunk and the latest commit on this branch, and store it as a diff in /tmp/feature.diff".  Then go to the redmine.org, create an issue, and attach /tmp/feature.diff to it.
110 1 John Goerzen
111 5 John Goerzen
If you wish to submit one patch for each commit, just run @git format-patch svn/trunk@.  You'll get one file generated for each commit, complete with the commit log.  Then you'll want to attach each of these at redmine.org.  Usually, though, you'll want the one big diff.
112
113
114
h1. External Links
115
116
* "Git homepage":http://www.git.or.cz/
117
* "5-Minute Git Guide":http://software.complete.org/site/wiki/GitGuide