Using git to hack on and contribute to Viking
From VikingWiki
git is a powerful distributed version control system that is very useful for hacking on and contributing to Viking. You can easily create branches to try out crazy hacks and experimental features, keep your own "personal version" of Viking, and easily "push" changes to a public repository so others can see them.
For developers who are thinking of giving a hand to viking, I'd suggest to start with git instead of svn. One of the most useful features is you can create/delete local branches as will.
As the stage git is now, I don't think there is any need to use any front end, but gitk or qgit does help visualise the history.
Contents |
One repo method
One method is to use one git repo for viking:
- leave branch "master" only for check in/out of sf svn
- my own version is on "local" branch.
- if you tend to do multiple unrelated work at the same time, you can put make separate topic branches based on "local". They are all developed, tested, put in use there.
- To commit any of those work to svn, rebase its branch to "master" and commit from there.
Here are some git commands typically used to achieve this.
Get Viking SVN repo
First create the git repo from svn repo:
$ git svn clone https://viking.svn.sourceforge.net/svnroot/viking --stdlayout
This will create a directory "viking", fill it with latest codes from svn, and create a branch called "master". All the following commands should be run after cd'ing to "viking".
Create your own personal branch
Create branch "local" for your own work:
$ git checkout -b local
Create a topic branch for a particular new feature
To create a new branch "print" (based on "local") for my work on printing:
$ git checkout -b print local
Bring the feature back to the upstream (master)
When done, I rebase "print" to "master", merge it to master before commit. Before running these commands, I normally update my "master" with current svn
$ git checkout print $ git rebase master $ git checkout master $ git merge print $ git svn dcommit
The way shown above is the most straight forward but I also often use different ways for different situation, here are some:
- Keep "print" on "local" and generate a diff. Then apply the diff to "master" before dcommit it. To generate diff, do
$ git diff local...print
- use git cherry-pick.
If you don't have write access to the Viking SVN repository, you can create your own fork from the Viking git repo for others to see, follow, and take patches from, and use git push to upload ("push") the changes to your public repository.
Update from upstream
- To update my "master" with current svn:
$ git checkout master $ git svn rebase --fetch-all
- To update my branch "local"
$ git checkout local $ git merge master
- To update my branch "print"
$ git rebase local print
git-completion.bash
git-completion.bash is found in the contrib/completion directory of the git source tree. Besides doing git command completion, it also puts the current branch name on the shell prompt. Now you can go wild and create branches for fun. Branches and tags are dirt cheap on git (compared to svn/cvs).
git-completion.bash comes with git source codes. I keep it in ~/.bash_completion/git-completion.bash and then add the following lines to ~/.bashrc
source ~/.bash_completion/git-completion.bash PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
Debian users may appreciate the line:
PS1='\u@\h:\W$(__git_ps1 "(%s)")\$ '
Howto share local branch on http://repo.or.cz/
This is how I did for "DEM" "fork" of viking, step by step
On http://repo.or.cz/ (Warning, if you have been playing on this site, restart your browser now. I had some bad experiences for not doing that)
- if you haven't registered as user yet, go to http://repo.or.cz/ and do so.
- You will need your ssh public key for this.
- I filled in the form on this page:
Project name (w/o the .git suffix): viking/DEM Admin password: XXXXX E-mail contact: qtonthat@gmail.com Hosting mode: Push mode Description: Viking with DEM
- Clicked on "Register"
- A page was shown and told me "Project viking/DEM was successfully set up."
- Clicked on "assign users" on the next sentence, which brought me to "Project Settings" page.
- On "Project Settings" page, I left everything untouched except entering my user name (as I registered previously on this site) into "Add user"
- Clicked "Update". It showed the same page again with my "user name" ticked.
- The "fork" registration completed here.
- To verify, I would go back to http://repo.or.cz/, find viking.git and click on the "+" or "forks" and then click on viking/DEM.git on the next page.
On my computer:
- On my git repo for viking I had a branch called "DEM".
- I added to .git/config the followings
[remote "DEM"]
url = ssh://qtonthat@repo.or.cz/srv/git/viking/DEM.git
push = DEM:DEM
- I did
$git push DEM
- Note that "DEM" here refers to DEM in 'remote "DEM"' in the config file.
- Git showed me that it was transferring the branch to repo.or.cz
- I went back to http://repo.or.cz/w/viking/DEM.git and check that the stuff was actually there.
- To update the public repo when I make changes to my local branch, I do
$git push DEM
