Source code management: Difference between revisions

From FreeCAD Documentation
m (→‎Developing: include tanderson's tip from the forum)
(couple of more tips...)
Line 7: Line 7:
This is only feasible as a transition. '''I strongly recommend the developers to switch to
This is only feasible as a transition. '''I strongly recommend the developers to switch to
git, as soon a possible! '''}}
git, as soon a possible! '''}}



== Access ==
== Access ==
Line 24: Line 23:
The read-only access does not prompt for a password.
The read-only access does not prompt for a password.


The read/write access uses your ssh password or ssh key to authorize your access. To perform write operations, your project administrator must have granted you write access to the repository.
The read/write access uses your ssh password or ssh key to authorize your access.
To perform write operations, your project administrator must have granted you write
Getting Started
access to the repository.

Note: - For all examples below, "USERNAME" represents your SourceForge.net user account.


'''Note:''' In all examples below, "USERNAME" represents your SourceForge.net user account.


=== How to clone the repository ===
=== How to clone the repository ===
Line 34: Line 33:
You can simply clone your remote repository and get working:
You can simply clone your remote repository and get working:


git clone ssh://USERNAME@free-cad.git.sourceforge.net/gitroot/free-cad/free-cad
git clone ssh://USERNAME@free-cad.git.sourceforge.net/gitroot/free-cad/free-cad REPONAME
cd REPONAME
cd REPONAME


The first time you try connecting to the free-cad.git.sourceforge.net host, you should see a message similar to the following:
The first time you try connecting to the free-cad.git.sourceforge.net host,
you should see a message similar to the following:


The authenticity of host 'free-cad.git.sourceforge.net (216.34.181.91)' can't be established.
The authenticity of host 'free-cad.git.sourceforge.net (216.34.181.91)' can't be established.
RSA key fingerprint is 86:7b:1b:12:85:35:8a:b7:98:b6:d2:97:5e:96:58:1d.
RSA key fingerprint is 86:7b:1b:12:85:35:8a:b7:98:b6:d2:97:5e:96:58:1d.
Are you sure you want to continue connecting (yes/no)?
Are you sure you want to continue connecting (yes/no)?


Before typing 'yes' to accept the host fingerprint, ensure the fingerprint is correct for the host. You can find a listing of SSH host keys in the SSH Host Key Fingerprints list. If you receive a host key warning, please contact the SourceForge.net team.
Before typing 'yes' to accept the host fingerprint, ensure the fingerprint is correct for the host.
You can find a listing of SSH host keys in the SSH Host Key Fingerprints list. If you receive a host
key warning, please contact the SourceForge.net team.


=== Setting your git username ===
=== Setting your git username ===


Users should commit to their project repository using their SourceForge.net username. If that is not already set globally, you can set it locally for the current Git repository like this:
Users should commit to their project repository using their SourceForge.net username.
If that is not already set globally, you can set it locally for the current Git repository like this:


git config user.name "YOUR NAME"
git config user.name "YOUR NAME"
git config user.email "USERNAME@users.sourceforge.net"
git config user.email "USERNAME@users.sourceforge.net"


You can now use some combination of "git add" and "git commit" commands to create one or more commits in your local repository.
You can now use some combination of "git add" and "git commit" commands to create one or more
commits in your local repository.



== Developing ==
== Developing ==

First of all '''never develop on the ''master'' branch!''' Create a local branch for development.
First of all '''never develop on the ''master'' branch!''' Create a local branch for development.
You can learn how to do this [http://book.git-scm.com/3_basic_branching_and_merging.html here].
You can learn how to do this [http://book.git-scm.com/3_basic_branching_and_merging.html here].


=== Publishing your work ===
=== Branching ===


An important feature of Git is that it is extremely easy to work with branches and merge
After done some changes on your local branch and commit it (this means commit ''locally'') you can
them together. Best practices recommend to create a new branch whenever you want to work
push your repository to the server. This opens your branch to the public and allows the
on a new feature. Creating a branch is done with:
main developers to review and integrate your branch into ''master''.

git branch myNewBranch
git checkout myNewBranch

or, both operation in one:

git checkout -b myNewBranch

you can always check in which branch you are with:

git branch

=== Committing ===

Once you did some work, you commit them with:

git commit -a

Unlike SVN, you need to specifically tell which files to commit (or all with the
-a option). Your text editor will open to allow you to write a commit message.

=== Publishing your work on the sourceforge repository===

After done some changes on your local branch and commit it (this means commit
''locally'') you can push your repository to the server. This opens your branch
to the public and allows the main developers to review and integrate your
branch into ''master''.


git push my-branch
git push my-branch


=== Guidelines for publishing your work ===
=== Publishing on another repository ===

Git also allows you to merge branches from more than one repository. If you don't
have read access to the sourceforge hosted FreeCAD Git repository, you can also setup
an account on any other free Git host such as [https://github.com/ github] or
[http://gitorious.org/ gitorious] and tell other people to get your changes from there.

=== Writing good commit messages ===


You should try to work in small chunks. If you cannot summarize your changes in one sentence, then it has probably been too long since you have made a commit. It is also important that you have helpful and useful descriptions of your work. For commit messages, FreeCAD has adopted a format mentioned in book Pro Git (see [[#Further Reading]]).
You should try to work in small chunks. If you cannot summarize your changes in one
sentence, then it has probably been too long since you have made a commit. It is also
important that you have helpful and useful descriptions of your work. For commit messages,
FreeCAD has adopted a format mentioned in book Pro Git (see [[#Further Reading]]).


Short (50 chars or less) summary of changes
Short (50 chars or less) summary of changes
Line 87: Line 128:
single space, with blank lines in between, but conventions vary here
single space, with blank lines in between, but conventions vary here


If you are doing a lot of related work, it has been suggested
If you are doing a lot of related work, it has been suggested [https://sourceforge.net/apps/phpbb/free-cad/viewtopic.php?f=10&t=2062&p=14887#p14886 here] that one should make as many commits large or small as makes sense for what you are working on using the short one sentence commit messages. When you want to merge, do a git log master..BRANCH and use the output as a basis for your quality commit message. Then when you merge to master use the --squash option and commit with your quality commit message. This will allow you to be very liberal with your commits and help to provide a good level of detail in commit messages without so many distinct descriptions.
[https://sourceforge.net/apps/phpbb/free-cad/viewtopic.php?f=10&t=2062&p=14887#p14886 here]
that one should make as many commits large or small as makes sense for what you are working
on using the short one sentence commit messages. When you want to merge, do a
git log master..BRANCH and use the output as a basis for your quality commit message.
Then when you merge to master use the --squash option and commit with your quality commit message.
This will allow you to be very liberal with your commits and help to provide a good level of detail
in commit messages without so many distinct descriptions.


== Further Reading ==
== Further reading ==


* [http://spheredev.org/wiki/Git_for_the_lazy Git for the lazy]
* [http://spheredev.org/wiki/Git_for_the_lazy Git for the lazy]

Revision as of 15:09, 25 December 2011

In future our main source code management tool will be git. This article explain how to use it and the general rules apply in case of FreeCAD.

For a while we keep up the SVN repository on sf.net. It is possible to commit changes

in SVN and Git. I will do from time to time a merge from one to the other via a gatekeeper repository.

This is only feasible as a transition. I strongly recommend the developers to switch to

git, as soon a possible!

Access

To access a Git repository, configure your Git client as follows :

 git://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad  (read-only)
 ssh://USERNAME@free-cad.git.sourceforge.net/gitroot/free-cad/free-cad (read/write) 

Access rules

We will give everyone interested in participating write access to the git repository as long as you stay away from master branch (tip).

Authentication

The read-only access does not prompt for a password.

The read/write access uses your ssh password or ssh key to authorize your access. To perform write operations, your project administrator must have granted you write access to the repository.

Note: In all examples below, "USERNAME" represents your SourceForge.net user account.

How to clone the repository

You can simply clone your remote repository and get working:

git clone ssh://USERNAME@free-cad.git.sourceforge.net/gitroot/free-cad/free-cad REPONAME
cd REPONAME

The first time you try connecting to the free-cad.git.sourceforge.net host, you should see a message similar to the following:

The authenticity of host 'free-cad.git.sourceforge.net (216.34.181.91)' can't be established.
RSA key fingerprint is 86:7b:1b:12:85:35:8a:b7:98:b6:d2:97:5e:96:58:1d.
Are you sure you want to continue connecting (yes/no)? 

Before typing 'yes' to accept the host fingerprint, ensure the fingerprint is correct for the host. You can find a listing of SSH host keys in the SSH Host Key Fingerprints list. If you receive a host key warning, please contact the SourceForge.net team.

Setting your git username

Users should commit to their project repository using their SourceForge.net username. If that is not already set globally, you can set it locally for the current Git repository like this:

git config user.name "YOUR NAME"
git config user.email "USERNAME@users.sourceforge.net"

You can now use some combination of "git add" and "git commit" commands to create one or more commits in your local repository.

Developing

First of all never develop on the master branch! Create a local branch for development. You can learn how to do this here.

Branching

An important feature of Git is that it is extremely easy to work with branches and merge them together. Best practices recommend to create a new branch whenever you want to work on a new feature. Creating a branch is done with:

git branch myNewBranch
git checkout myNewBranch

or, both operation in one:

git checkout -b myNewBranch

you can always check in which branch you are with:

git branch

Committing

Once you did some work, you commit them with:

git commit -a

Unlike SVN, you need to specifically tell which files to commit (or all with the -a option). Your text editor will open to allow you to write a commit message.

Publishing your work on the sourceforge repository

After done some changes on your local branch and commit it (this means commit locally) you can push your repository to the server. This opens your branch to the public and allows the main developers to review and integrate your branch into master.

git push my-branch

Publishing on another repository

Git also allows you to merge branches from more than one repository. If you don't have read access to the sourceforge hosted FreeCAD Git repository, you can also setup an account on any other free Git host such as github or gitorious and tell other people to get your changes from there.

Writing good commit messages

You should try to work in small chunks. If you cannot summarize your changes in one sentence, then it has probably been too long since you have made a commit. It is also important that you have helpful and useful descriptions of your work. For commit messages, FreeCAD has adopted a format mentioned in book Pro Git (see #Further Reading).

Short (50 chars or less) summary of changes

More detailed explanatory text, if necessary.  Wrap it to about 72
characters or so.  In some contexts, the first line is treated as the
subject of an email and the rest of the text as the body.  The blank
line separating the summary from the body is critical (unless you omit
the body entirely); tools like rebase can get confused if you run the
two together.

Further paragraphs come after blank lines. 

 - Bullet points are okay, too

 - Typically a hyphen or asterisk is used for the bullet, preceded by a
   single space, with blank lines in between, but conventions vary here

If you are doing a lot of related work, it has been suggested here that one should make as many commits large or small as makes sense for what you are working on using the short one sentence commit messages. When you want to merge, do a git log master..BRANCH and use the output as a basis for your quality commit message. Then when you merge to master use the --squash option and commit with your quality commit message. This will allow you to be very liberal with your commits and help to provide a good level of detail in commit messages without so many distinct descriptions.

Further reading

Available translations of this page: