RedmineGitTracking » History » Version 7
Mischa The Evil, 2009-01-09 12:48
Restructed page, removed obsolete spaces, modded caution-notice and updated last-change date.
1 | 7 | Mischa The Evil | {{>toc}} |
---|---|---|---|
2 | 6 | Eric Davis | |
3 | 1 | John Goerzen | h1. Using Git to contribute to Redmine |
4 | |||
5 | 7 | Mischa The Evil | 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. |
6 | 1 | John Goerzen | |
7 | 7 | Mischa The Evil | Caution: The git repository at complete.org isn't kept current, as of this writing the last change was done Mon, 8 Sep 2008. Cloning the "GitHub mirror":http://github.com/edavis10/redmine/tree/master is recommended for the latest development work. |
8 | 1 | John Goerzen | |
9 | 7 | Mischa The Evil | If you were looking for Subversion instructions, they can be found on the [[Download|download page]]. |
10 | 3 | John Goerzen | |
11 | 7 | Mischa The Evil | h2. Initialization |
12 | |||
13 | 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. |
||
14 | 1 | John Goerzen | To start out, run these commands: |
15 | |||
16 | <pre> |
||
17 | git clone git://git.complete.org/branches/redmine-integration |
||
18 | cd redmine-integration |
||
19 | git config --add remote.origin.fetch +refs/remotes/svn/*:refs/remotes/svn/* |
||
20 | git fetch |
||
21 | </pre> |
||
22 | |||
23 | h2. Exploration |
||
24 | |||
25 | You can see all the branches that Git obtained for you: |
||
26 | |||
27 | <pre> |
||
28 | git branch -r | less |
||
29 | </pre> |
||
30 | |||
31 | 7 | Mischa The Evil | You'll see output like this (many lines omitted here): |
32 | 1 | John Goerzen | |
33 | 2 | John Goerzen | <pre> |
34 | 1 | John Goerzen | origin/HEAD |
35 | origin/fb-bug-259-git |
||
36 | origin/fb-bug-261-issue-redirect |
||
37 | origin/fb-bug-641-context-done |
||
38 | svn/git |
||
39 | svn/issue_relations |
||
40 | svn/mailing_lists |
||
41 | svn/tags/0.6.3 |
||
42 | svn/tags/0.6.3@1011 |
||
43 | svn/time |
||
44 | svn/trunk |
||
45 | svn/wiki |
||
46 | </pre> |
||
47 | |||
48 | 7 | Mischa The Evil | 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. |
49 | 1 | John Goerzen | |
50 | You'll base your work off these branches. |
||
51 | |||
52 | 7 | Mischa The Evil | h2. Starting Your Feature |
53 | 1 | John Goerzen | |
54 | 7 | Mischa The Evil | 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. |
55 | 2 | John Goerzen | |
56 | 7 | Mischa The Evil | You'll want to base your patch on svn trunk. So you'll set up a branch like so: |
57 | 2 | John Goerzen | |
58 | <pre> |
||
59 | $ git branch my-feature svn/trunk |
||
60 | Branch my-feature set up to track remote branch refs/remotes/svn/trunk. |
||
61 | $ git checkout my-feature |
||
62 | </pre> |
||
63 | |||
64 | 7 | Mischa The Evil | 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. |
65 | 2 | John Goerzen | |
66 | 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. |
||
67 | |||
68 | You can run @git branch@ to see what branch you're on -- it'll have an asterisk next to it, like this: |
||
69 | |||
70 | <pre> |
||
71 | $ git branch |
||
72 | master |
||
73 | * my-feature |
||
74 | </pre> |
||
75 | |||
76 | 7 | Mischa The Evil | h2. Working on your feature |
77 | 1 | John Goerzen | |
78 | Now that you have made your branch, it's time start work. |
||
79 | |||
80 | 3 | John Goerzen | Here are some commands you may want to use: |
81 | |||
82 | |_.task|_.command| |
||
83 | |Commit outstanding changes|@git commit -a@| |
||
84 | |Add a new file to the repo|@git add filename@| |
||
85 | |Remove a file from the repo and working directory|@git rm filename@| |
||
86 | 1 | John Goerzen | |Rename a file in repo and working directory|@git mv oldname newname@| |
87 | |View history|@git log@| |
||
88 | |Get help|@git commandname --help@| |
||
89 | 3 | John Goerzen | |
90 | 7 | Mischa The Evil | Note that @git command@ is the same as @git-command@. You can use @man git-command@ to see the manpage for any Git command. |
91 | 1 | John Goerzen | |
92 | 7 | Mischa The Evil | h2. Merging with trunk |
93 | 4 | John Goerzen | |
94 | 7 | Mischa The Evil | 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: |
95 | 4 | John Goerzen | |
96 | <code> |
||
97 | git fetch |
||
98 | git rebase svn/trunk |
||
99 | 5 | John Goerzen | </code> |
100 | 4 | John Goerzen | |
101 | 7 | Mischa The Evil | h2. Submitting your Patch |
102 | 4 | John Goerzen | |
103 | 7 | Mischa The Evil | When you're done working on your patch, make sure you have committed it to Git. Then you can generate diffs. |
104 | 4 | John Goerzen | |
105 | 7 | Mischa The Evil | 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: |
106 | 4 | John Goerzen | |
107 | <code> |
||
108 | git diff svn/trunk..HEAD > /tmp/feature.diff |
||
109 | </code> |
||
110 | |||
111 | 7 | Mischa The Evil | 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. |
112 | 5 | John Goerzen | |
113 | 7 | Mischa The Evil | 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. |
114 | 5 | John Goerzen | |
115 | 7 | Mischa The Evil | h2. External Links |
116 | 5 | John Goerzen | |
117 | * "Git homepage":http://www.git.or.cz/ |
||
118 | * "5-Minute Git Guide":http://software.complete.org/site/wiki/GitGuide |