gaf: Fix memory leak
[geda-gaf.git] / docs / wiki / geda-scm.html
blob9a8cb0c7a74d8a908c28e0a913ddd7cafe411462
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html>
4 <head>
5 <link rel="stylesheet" media="screen" type="text/css" href="./style.css" />
6 <link rel="stylesheet" media="screen" type="text/css" href="./design.css" />
7 <link rel="stylesheet" media="print" type="text/css" href="./print.css" />
9 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10 </head>
11 <body>
13 <p>
14 <em>Translations of this page are also available in the following languages:</em> <a href="geda-scm.ru.html" class="wikilink1" title="geda-scm.ru.html">Русский</a>.
15 </p>
17 <h1 id="gedausesgit">gEDA uses git</h1>
18 <div class="level1">
20 <p>
21 gEDA uses <strong>git</strong> for source code management. git is a distributed version control system, where every user has his or her own full copy of the revision history.
22 </p>
23 <ul>
24 <li class="level1"><div class="li"> official git website</div>
25 </li>
26 <li class="level1"><div class="li"> git documentation online</div>
27 </li>
28 </ul>
30 <p>
31 Some nice tutorials:
32 </p>
33 <ul>
34 <li class="level1"><div class="li"> comprehensive set of tutorials at atlassian.com</div>
35 </li>
36 <li class="level1"><div class="li"> GitSvnCrashCourse -- git courses for SVN users</div>
37 </li>
38 <li class="level1"><div class="li"> Git - The Simple Guide -- very concise and condensed cheat sheet style tutorial</div>
39 </li>
40 </ul>
42 </div>
44 <h2 id="read-onlyaccessthegedarepositories">Read-only access the geda repositories</h2>
45 <div class="level2">
47 <p>
48 To clone the geda-gaf.git repository (or any repository hosted at git.geda-project.org) using anonymous git access:
49 </p>
50 <pre class="code">git clone git://git.geda-project.org/geda-gaf.git</pre>
52 <p>
54 </p>
55 <pre class="code">git clone git://git.geda-project.org/pcb.git</pre>
57 <p>
58 For different repositories hosted at git.geda-project.org, just substitute the last part of the above URL.
59 </p>
61 <p>
62 There is a cgit interface to the repositories of the various projects. Just point a www browser to http://git.geda-project.org/ .
63 </p>
65 </div>
67 <h2 id="featurebranches">Feature branches</h2>
68 <div class="level2">
70 <p>
71 Branches are a major feature of git. The geda project uses feature branches to test non-trivial changes. Once they are assessed as useful, the changes a branch represents gets merged into the main head. You can try and test a feature branch even if you don&#039;t have write access to the git repository of geda-project, yet.
72 </p>
74 </div>
76 <h3 id="listallbranchesofaproject">List all branches of a project</h3>
77 <div class="level3">
79 <p>
80 To list all branches of a project available on the geda-project server cd to your local copy of the project and emit this git command:
81 </p>
82 <pre class="code">$ git branch -r</pre>
84 </div>
86 <h3 id="trackafeaturebranch">Track a feature branch</h3>
87 <div class="level3">
89 <p>
90 This will create a branch with the name <code>&lt;local name&gt;</code> in your local repository, which tracks the <code>&lt;remote name&gt;</code>&#039;d branch.
91 </p>
92 <pre class="code">$ git checkout --track -b &lt;local name&gt; origin/&lt;remote name&gt;</pre>
94 <p>
95 Go ahead and build the application from the branch as described by the <a href="geda-gaf_building_git_version.html" class="wikilink1" title="geda-gaf_building_git_version.html">build instructions</a>. By default the command <code>make install</code> will copy the binaries to <code>/usr/local/*</code>. That way, it will not interfere with an install done by your linux distribution. You may use full paths, symbolic links or aliases to pick which version to use.
96 </p>
98 </div>
100 <h3 id="communicateyourexperience">Communicate your experience</h3>
101 <div class="level3">
104 Generally, there will be a launchpad bug associated with the feature of the branch. Please report your experience with the branch there. Your input will influence whether or not the feature will make into mainstream. There is a group of users and developers who keep an eye on changes to bug reports. They will get noticed by email.
105 </p>
108 For additional visibility you may report your experience on the mailing list <a href="geda-mailinglists.html" class="wikilink1" title="geda-mailinglists.html">geda-user</a>. It may even spark a discussion. As with all forms of general online discussion, the note may get archived and gradually be forgotten without any action taken.
109 </p>
111 </div>
113 <h2 id="formatapatchtosendtothedevelopers">Format a patch to send to the developers</h2>
114 <div class="level2">
117 The simplest possible way includes all changes since the local repository was syncronized with the repository at geda-project.org:
118 </p>
119 <pre class="code">$ git diff &gt; name_of_patchfile</pre>
122 A more complicated way with more control on what the patch contains:
123 </p>
124 <pre class="code">$ git add -i # select files to be committed
125 $ git status # check you&#039;re committing what you think you&#039;re committing
126 $ git commit # create a commit
127 $ git format-patch -1 # create a patch file based on that commit</pre>
130 This will output a filename which contains the patch. Be sure to look at the documentation for format-patch for more information. This file can be e-mailed to developers who have write access and can be applied using git apply.
131 </p>
133 </div>
135 <h2 id="accesstherepositorywithwritepermission">Access the repository with write permission</h2>
136 <div class="level2">
139 For developer git access, you should write DJ Delorie or Traumflug an email with your SSH public key and your preferred user name. They&#039;ll install this key on the server, then. Having done so, the git URL to push to is (note the <em>:65</em>):
140 </p>
141 <pre class="code">ssh://git@git.geda-project.org:65/&lt;repository&gt;.git</pre>
144 Note: If you&#039;re having trouble pushing commits upstream, make sure you&#039;re using git 1.5 or newer.
145 </p>
148 Accordingly, to grab a repository copy with write privileges you&#039;d do this:
149 </p>
150 <pre class="code">git clone ssh://git@git.geda-project.org:65/&lt;repository&gt;.git</pre>
153 If you have a read-only clone already you can change it to one with write access:
154 </p>
155 <pre class="code">git remote remove origin
156 git remote add origin ssh://git@git.geda-project.org:65/&lt;repository&gt;.git</pre>
159 Having this done, your local clone works just as before, just a <code>git push origin &lt;branch&gt;</code> succeeds.
160 </p>
162 </div>
164 <h3 id="useauniquesshkeyforgeda">Use a unique SSH key for gEDA</h3>
165 <div class="level3">
168 You can use a separate key for accessing the gEDA git access. This has no further advantage other than having a unique key. In this case you may also need to add a line to your ~/.ssh/config file to specify this alternate key:
169 </p>
170 <pre class="code">Host git.geda-project.org
171 Port 65
172 IdentityFile ~/.ssh/gedaproject_dsa</pre>
175 Note, the file you refer to here is the private key. By contrast, the file you send for the server side is the corresponding public key.
176 </p>
178 </div>
180 <h2 id="commitchanges">Commit changes</h2>
181 <div class="level2">
183 </div>
185 <h3 id="setupuserinformation">Set up user information</h3>
186 <div class="level3">
189 You should make sure that your username &amp; e-mail address are set in your git configuration file.
190 </p>
191 <pre class="code">$ git config --global user.name &quot;Your Name Comes Here&quot;
192 $ git config --global user.email you@yourdomain.example.com</pre>
194 </div>
196 <h3 id="commitpatchesfromothercontributors">Commit patches from other contributors</h3>
197 <div class="level3">
200 If you apply a patch from someone else (e.g. from a launchpad patch record) there are a few things to consider.
201 Git stores two different names and e-mail addresses for a given commit: the &quot;author&quot; of the patch, and the &quot;committer&quot; of the patch, so these details must be set correctly when making the commit.
202 </p>
205 First of all, check a few things:
206 </p>
207 <ul>
208 <li class="level1"><div class="li"> You have the latest version of the patch.</div>
209 </li>
210 <li class="level1"><div class="li"> The author of the patch is happy for it to be committed (and wasn&#039;t still working on it)</div>
211 </li>
212 <li class="level1"><div class="li"> That the you&#039;re happy with the patch, and taking responsibility for committing those changes.</div>
213 </li>
214 </ul>
217 For simplicity, start from an unmodified up-to date tree (git status shows no changes).
218 </p>
221 Apply the patch as usual (as an example):
222 </p>
223 <pre class="code">$ patch -p1 &lt; example_changes.patch</pre>
226 You can also use the git apply command:
227 </p>
228 <pre class="code">$ git apply example_changes.patch</pre>
231 If the patch needs any minor editing before it is committed (eg. white-space changes), please inform the author this was done.
232 They may have other work based on their patch and will want to know if there were changes to the applied version.
233 </p>
234 <div class="noteclassic">This is easy to miss accidentally if your editor introduces tabs. Please avoid letting it do so!
235 </div>
237 For every file changed, added or removed, you need to inform git before it will commit the changes. To see the modified files, run:
238 </p>
239 <pre class="code">$ git status</pre>
242 For speed, the command:
243 </p>
244 <pre class="code">$ git add -u</pre>
247 will update all files which git tracks, including any files which were deleted.
248 </p>
251 For adding any new files the patch introduced, use the command
252 </p>
253 <pre class="code">$ git add new_file.c</pre>
256 Note: git add also takes wild-cards.
257 </p>
260 Commit the patch, making sure that the Author&#039;s name and e-mail address are specified:
261 </p>
262 <pre class="code">$ git commit --author &quot;Author&#039;s Name Comes Here &lt;author@example.com&gt;&quot;</pre>
265 As an alternative, you can set the GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL environment variables before issuing the normal commit command
266 </p>
268 </div>
270 <h3 id="writegoodcommitmessages">Write good commit messages</h3>
271 <div class="level3">
274 The commit message format is as follows: a *strictly* one-line summary of the patch, followed by a blank line, followed by a long description. If you can fit the whole description of the patch on one line, that&#039;s fine; don&#039;t bother with the long description.
275 </p>
278 The one-line summary is used for generating e-mail subject lines, and for the gitk &amp; gitweb log displays. Having a good one-line summary is really useful, because it means those tools can be used to quickly find a commit of interest.
279 </p>
282 <strong>Do not</strong> put a list of files changed into commit messages. This information can be trivially obtained using the git tools.
283 </p>
286 Example:
287 </p>
288 <pre class="code">Added new GedaList class derived from GObject
290 This abstracts a GList with API for write access. Its main use is in list
291 change notification, as it emits a &quot;changed&quot; g_signal when modified.
292 Read only access to the underlying GList is provided by an accessor,
293 currenly implemented as a macro.</pre>
295 </div>
297 <h2 id="keepthelocalcopycurrent">Keep the local copy current</h2>
298 <div class="level2">
301 For those who are are not merging changes back into the central git repository you can run:
302 </p>
303 <pre class="code">$ git pull</pre>
306 However, for those of you who are going to be pushing your changes back into the central git repository, using git pull will clutter up the history with merge messages (&quot;Merge branch &#039;master&#039;&quot;). To avoid this you should run:
307 </p>
308 <pre class="code">$ git fetch
309 $ git rebase origin</pre>
311 </div>
313 <h2 id="commitchangestothelocalgitrepository">Commit changes to the local git repository</h2>
314 <div class="level2">
315 <pre class="code">$ git commit -a</pre>
318 This command will find all changed files that git knows about (added with git-add) and prompt you for a commit message. Be sure to follow the above commit message convention if you plan on pushing your changes to the central repository.
319 </p>
322 If you want to commit files in the current directory or want to explicitly commit only certain files, do not specify the -a flag and/or specify the individual filenames on the command line like:
323 </p>
324 <pre class="code">$ git commit filename1 filename2</pre>
326 </div>
328 <h2 id="undoanyuncommittedlocalchanges">Undo any uncommitted local changes</h2>
329 <div class="level2">
330 <pre class="code">$ git checkout -f</pre>
333 Note this will discard any changes to any files that are being tracked by git.
334 </p>
337 If you want to just discard edits in a single file, just run:
338 </p>
339 <pre class="code">$ git checkout path/to/file/to/discard</pre>
342 If you want to discard all edits from the current directory and downward recursively, just run:
343 </p>
344 <pre class="code">$ git checkout .</pre>
346 </div>
348 <h2 id="fixalessthanperfectlastcommit">Fix a less than perfect last commit</h2>
349 <div class="level2">
350 <pre class="code">$ Edit whatever files
351 $ git commit --amend filename1..filenameN</pre>
354 This will pickup any changes you made and recommit them again with the previous commit message.
355 </p>
357 </div>
359 <h2 id="createapersonalizedbranch">Create a personalized branch</h2>
360 <div class="level2">
363 If you have write permission to the git repository of the gEDA project, you can create personalized branches for your patches. This is recommend to facilitate tests, review and finally application of the patches to the master branch of the application. For this purpose a personalized name space is available in the git repositories. The prefix of this name space is <code>home/&lt;user_name&gt;/</code>, where <code>&lt;user_name&gt;</code> is your user name.
364 </p>
367 First create the branch locally and simultaneously switch to it as the current branch:
368 </p>
369 <pre class="code"> $ git checkout -b home/&lt;user_name&gt;/&lt;name_of_the_branch&gt;</pre>
372 Make some changes. Stage the changes and issue a commit:
373 </p>
374 <pre class="code"> $ git stage &lt;files to commit&gt;
375 $ git commit -F &lt;commit_message&gt;</pre>
378 Where <code>&lt;commit_message&gt;</code> points to a file which contains the commit message.
379 </p>
382 To publish the changed branch to the remote repository do:
383 </p>
384 <pre class="code"> $ git push origin home/&lt;user_name&gt;/&lt;name_of_the_branch&gt;</pre>
387 The first push to a branch creates it on the remote server.
388 For a little more convenience, you can advise git to always push to the current branch:
389 </p>
390 <pre class="code"> $ git config --global push.default current</pre>
393 Skip the option <code>--global</code> if you want this to be active only in this particular git project. With this directive the command above reduces to a mere
394 </p>
395 <pre class="code"> $ git push
396 </pre>
398 </div>
400 <h2 id="deleteapersonalizedbranch">Delete a personalized branch</h2>
401 <div class="level2">
404 In case you&#039;d rather not have your branch sitting indefinitely in the remote repository, you can issue a delete directive. To delete the branch on the server do:
405 </p>
406 <pre class="code"> $ git push origin --delete home/&lt;user_name&gt;/&lt;name_of_the_branch&gt;</pre>
409 To delete the branch on the local repository, too:
410 </p>
411 <pre class="code"> $ git branch --delete home/&lt;user_name&gt;/&lt;name_of_the_branch&gt;
412 </pre>
414 </div>
416 <h2 id="fetchadevelopmentbranchfromotherpeople">Fetch a development branch from other people</h2>
417 <div class="level2">
420 Beside the http://git.geda-project.org/ repository we have a mirror of that repository at http://repo.or.cz/w/geda-gaf.git. Some of the developers have forks of that repository with new feature branches.
421 </p>
424 If you like to test one of the feature branches you have to fetch it from their repository.
425 The easiest way to get a branch is to use the fetch command.
426 </p>
427 <pre class="code"> $ git fetch repository_url remote_branchname:local_branchname</pre>
430 <strong>Examples:</strong>
431 Getting the <em>cairo_experiment</em> branch from Peter C. would look like this:
432 </p>
433 <pre class="code"> $ git fetch git://repo.or.cz/geda-gaf/pcjc2.git cairo_experiment:peters_cairo_experiment</pre>
436 Now you can switch to the local copy of the branch <em>peters_cairo_experiment</em> and play with it.
437 </p>
440 It is also possible to add multiple remote forks into the local repository:
441 </p>
442 <pre class="code"> $ git remote add &lt;name&gt; &lt;url&gt;
443 $ git fetch &lt;name&gt;</pre>
446 As long as &lt;name&gt; is unique you will be able to follow their work without the
447 need to create local branches. With a tool like gitk it is now possible to keep
448 an eye on development in various feature branches on various forks:
449 </p>
450 <pre class="code"> $ gitk --all</pre>
453 <strong>Examples:</strong>
454 </p>
455 <pre class="code"> $ git remote add peter-b https://github.com/peter-b/geda-gaf.git
456 $ git fetch peter-b
457 $ git remote add gareth8118 https://github.com/gareth8118/geda-gaf.git
458 $ git fetch gareth8118
459 $ git remote add bert https://github.com/bert/geda-gaf.git
460 $ git fetch bert
461 $ gitk --all</pre>
464 Now gitk can become quite filled up, but <strong>File</strong>-&gt;<strong>List references</strong> (<kbd>F2</kbd>) will open
465 a dialog for easier navigation.
466 </p>
469 Updating favourite remotes will then boil down to:
470 </p>
471 <pre class="code"> $ git fetch --all</pre>
473 </div>
475 <h2 id="recoverfromareallymesseduplocalrepository">Recover from a really messed up local repository</h2>
476 <div class="level2">
479 First off, do not push any repository that you think is somehow messed up. Ask one of the experienced git people first.
480 </p>
483 Second, the command that will really save your bacon is git-reflog. Using it works something like this:
484 </p>
485 <pre class="code"> $ git reflog
486 086908e... HEAD@{0}: cherry-pick: Last minute updates to the READMEs for all pro
487 2a79a23... HEAD@{1}: checkout: moving to master
488 2a79a23... HEAD@{2}: checkout: moving to master
490 $ git reset --hard HEAD@{1}</pre>
493 The last command (git reset --hard ...) will rollback all your changes to the &quot;checkout: moving to master&quot;. Remember: don&#039;t panic! Most things are fixable when using git.
494 </p>
496 </div>
497 </body>
498 </html>