{{caution|This article is out of date, please see the [[Git_svn|article on using git-svn]] for a more appropriate development strategy.}}
== Motivation ==
Subversion needs an online repository, to store each commits. Subsequent calls to '''svn diff > patch''' will generate the difference according to the last revision. Therefore the development at the moment, require to
== Initialization of git ==
Navigate to the root folder of the branch of relax, you want to develop. Initialize with: git initThen follow the this post [[Git_svn#relax_branches_at_github | relax_branches_at_github]]
=== Setup commit information ===
=== Preparation ===
As an example, we can take the development of the NMRPipe SeriesTab reader: [https://gna.org/support/index.php?3043 sr #3043: Support for NMRPipe seriesTab format *.ser]
git add lib/software/nmrpipe.py
git commit
commit messageWe are going to make a support request '''sr''' branch. [http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging See ref. on branching]. In this branch we add the files we would like to track for changes. Then we create a branch '''seriestab''' from '''sr'''. We then track and create patches of the differences between '''seriestab''' and '''sr'''. Create the support request '''sr''' branch. git co -b sr master<source lang="text"> # See all branchesAdded git br -a Then we create the '''nmrpipe into ''' branch (because we edit nmrpipe.py), from where we will create the patch according to the differences of the '''sr''' branch. git</source>co -b nmrpipe sr
# To see the commit message=== Checking out a development branch ===This section is modified from a how-to for [http://codeprairie.net/blogs/chrisortman/archive/2008/01/14/creating-subversion-patches-with-git log # Or see last changes by.aspx Creating subversion patches with git log -p]. We want to be able to create patches and commit messages, which are seamless to patch into the subversion relax repository.
=== Modification 1 ===
Then we modifylib/software/nmrpipe.py, and add following
<source lang="python">
# Python module imports.
from lib.errors import RelaxError
</source>
Then we make a patch
git diff > nmrpipe1
We add the change to be recorded
git add lib/software/nmrpipe.py
# OR use this, to add changes from all tracked files
git add -u
Then we commit
git commit
Or see last changes by
git log -p
Now create your [[Git_patch | git patch]], comparing to the sr branch
git format-patch sr --stdout > nmrpipe.patch
=== Modification 2 ===
"""
</source>
Then we make a patch
git diff > nmrpipe2
We add the change to be recorded
git add lib/software/nmrpipe.py
# OR use this, to add changes from all tracked files
git add -u
Then we commit
git commit
Or see last changes by
git log -p -1
Now create your patches, comparing to the sr branch
git format-patch sr --stdout > nmrpipe2.patch
This should provide you with a second patch files, with more commits.
=== Getting an overview ===
[http://git-scm.com/book/en/Git-Basics-Viewing-the-Commit-History This section is prepared from this site].
Export both commit message and change to last commit to file
git log -p -1
git log -p -1 > nmrpipe2_log
Using a GUI to Visualize History. If you like to use a more graphical tool to visualize your commit history, you may want to take a look at a Tcl/Tk program called gitk that is distributed with Git. Gitk is basically a visual git log tool, and it accepts nearly all the filtering options that git log does. Type gitk on the command line in your project.
gitk
Let's review how we can change older commit messages, [http://stackoverflow.com/questions/8824971/how-to-git-amend-older-commit how-to amend older commit]. We want to change the commit message we made some commits ago
To find out, how long we would like to go back, we use the log
git log
We would like change the commit message with commit hash sha1 of ('''833b91e6064cc8175ad741757ada25edd52c2cce''')
git rebase -i 833b91e6064cc8175ad741757ada25edd52c2cce~1
# Instead of 'sha1' you can use 'HEAD~N', where N is the number of commits before 'HEAD'
git rebase -i HEAD~2
Now mark the ones you want to amend with reword '''r''' (replace pick). Now save and exit editor.<br>
In the next editor, you can then write the new message. Save and exit editor.
Now create your patch, comparing to the sr branch
git format-patch sr --stdout > nmrpipe3.patch
=== Continuation ===
You continue with this cycle.
* Modify code
* Track the change
git add -u
* Make a commit message
git commit
== Finishing up ==
=== Complete test suite ===
First we test if we pass the test we setup for ourself
Now create your patches, comparing to the sr branch
git format-patch sr --stdout > nmrpipe.patch
Then upload the [[git_patch|git patch]] to the [https://gna.org/support/?group=relax support tracker].
== Reviewing suggestions and modify commit ==
There were a number of [http://article.gmane.org/gmane.science.nmr.relax.devel/4120 suggestions] to the patches from {{relax developer link|username=bugman|text=Edward}}.
=== Squash commits ===
[http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html You can squash commits], which essentially take smaller commits and combine them into larger ones. This can be useful if you’re are wrapping up the day’s work of code. Then you can also prepare a better commit message.
First get an overview, over which commits should be squashed
git log
Let's say you wan't to squash the last 6 commits. Set HEAD~6+1.
git rebase -i HEAD~7
In the pop-up editor, for all the commits who should be squashed, replace '''pick''' with '''s''' or '''squash'''. Do not change the '''pick''' for the first commit.
Save and exit editor.
Now compose a new commit message, which can be combined of the earlier commit messages. Comment out lines with "#" which should not be added.
<source lang="text">
Completed NMRPipe SeriesTab reader
Progress sr #3043: (https://gna.org/support/index.php?3043) Support for NMRPipe seriesTab format *.ser
Completed NMRPipe SeriesTab reader for assignment according to SPARKY format.
Changes implemented according to: http://article.gmane.org/gmane.science.nmr.relax.devel/4120
The above test, showed that the reading function had to be adjusted. So now we create a new branch, which is based on the branch we last edited. Meaning we copy the content of the modified files.
git co -b spectrum nmrpipe
git diff --stat --color nmrpipe..spectrum
The last line, should show an empty line for "no changes".
Now we change spectrum.py in read(), # NMRPipe SeriesTab, and add a commit message to each commit.
=== Finishing up ===
Delete old patches
rm *.patch
First change to the first branch we made changes is