Development/Git For LibreOffice Developers
Git is a(DVCS). It is a very powerful yet simple system, but if you are unfamiliar with DVCS, it can be confusing. Thankfully there are great resources on the web to learn about Git. If you are not familiar with it, you should visit:
- http://pcottle.github.com/learnGitBranching/ for excellent visualized learning-by-doing.
- http://git-scm.com/ for the dry theory or
- Git is a Directed Acyclic Graph (archived by ) -- if you know what a DAG is this is the quickest theory explaination
- http://mirror.linux.org.au/linux.conf.au/2013/ogv/Git_For_Ages_4_And_Up.ogv for a easy and visual explanation.
- https://www.youtube.com/watch?v=hkBVAi3oKvo <- needs to be tested with LibreOffice ;)
- http://who-t.blogspot.de/2009/12/on-commit-messages.html How to write good commit messages.
- http://ibrokegit.com/ has good emergency help, if things are messed up somehow.
The rest of this article will assume a basic working knowledge of Git.
Most of LibreOffice source code is in the
core git repository, but a few modules are in separate repositories,
dictionaries. In most cases you probably won’t have to modify these repositories.
Managing Git branches
- See: Development/Branches
Hack and commit on a stable branch
Stable branches are created from
master or another stable branch to stabilize the code base for the release and further maintenance updates. There are some rules during the beta phase:
- Allowed are any changes in translations
- Allowed are any bug fixes
- Allowed are late features that are approved by the Engineering Steering Committee
There are more strict rules during the release candidate phase:
- Allowed are safe fixes that are reviewed by another person, see below
- Allowed are changes in translations; it is recommended to ask for review on the native l10n mailing list
Please, do not commit the fixes directly during the RC phase. Instead, please send your patch to gerrit or ask another developer for review on the email@example.com mailing list, personal mail, on IRC or via the related bug entry. The fix should be committed by the reviewer using:
git commit -s --author='Author name <firstname.lastname@example.org>'
What to do when
git pull -r does not want to operate
It is usually due to local changes in your repository. You can either get rid of them, using:
git checkout -f git pull -r
or stash them temporarily, and get them back again after the git pull -r:
git stash git pull -r git stash pop
Reset your modified repo to a pristine “vanilla” repository
~/loroot $ git reset --hard origin/master
will discard all your local changes (whether committed or not) and reset the current branch that you are on to the one on the remote repository.
Reorder, squash and in general tweak your local history:
git rebase -i
git rebase -i is a powerful tool that allows you to “rewrite” your local history.
|Warning:||This should only be done on commits that have not been pushed to master or a release branch yet!!!|
Let’s say you are on
master and the last 3 commits are A,B,C=HEAD but C is actually a correction of the commit A that you missed before committing B. So what you would want to do is to merge A and C together and end-up with A',B as history.
To do that you can
git branch safehead HEAD
This is just in case something goes very wrong and you want to just undo everything and go back to the initial sate
git rebase -i HEAD~3
This should bring, in your favorite editor (as set by the variable
$EDITOR) a list of the last 3 commits, from the oldest to the newest (the reverse order than normally in git log), so C is the last of the list:
pick 726fe9c enable localization of extension descriptions in mysqlc pick 9ab6ecf fix en-US only build pick a18bfb0 Revert "enable localization of extension descriptions in sdext" # Rebase 1846533..a18bfb0 onto 1846533 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x <cmd>, exec <cmd> = Run a shell command <cmd>, and stop if it fails # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. #
Edit it, moving commit C one-up and changing its action to
pick 726fe9c enable localization of extension descriptions in mysqlc squash a18bfb0 Revert "enable localization of extension descriptions in sdext" pick 9ab6ecf fix en-US only build
Then save and exit the editor.
Now you can edit the commit message of the merged commit:
# This is a combination of 2 commits. # The first commit's message is: enable localization of extension descriptions in mysqlc Change-Id: I7141eea0fe7f72408da0d2a5ebe4a5e2891b6b7d # This is the 2nd commit message: Revert "enable localization of extension descriptions in sdext" Change-Id: Iff01d31792a13a14ea720c477417217af0c01642
|Note:||If you intend to push the commit to gerrit, the
Once you have combined the 2 commit messages, save and exit again.
If everything went nicely you should be on
master with your HEAD on B and A+C fused into one commit A', just before B. If things went wrong and you are lost:
git rebase --abort
If things are not reverted to the way they should (compounded wrongness :-) you can
git reset --hard safehead
to pretend nothing ever happened :-)
Getting and using commit access
In order to get commit access you need to be “sponsored”. Once you’ve submitted patches and got yourself recognised this won’t be a problem, but it’s best to wait until you’re asked. Once you’ve been asked (or asked for someone to sponsor you), you need to get an account