Saturday, December 31, 2011

Frequently Used Git Commands with Github

simple log of personal usage.

Add tag

1. add: git add -a TAG_NAME (then git bash will ask you to add tag message)

2. prerss 'I', input some message, press 'ESC', input 'wq' then press 'ENTER'

3. push tag: git push --tags

Clone a project
git clone [url] : clone by url

Create a file
touch [fileName]

add changed:
before commit the any change, you should add it
git add [the file path to add] : add specific file
git add . : add all

git add -A : also remove index of deleted files
(will add new files, as well as updating modified content in your index, and remove files that are no longer in the working directory.)
Reference: Removing Deleted Files from your Git Working Directory

revert change:
git reset --hard : reset HEAD, index and working tree
git reset [--<mode>] [<commit>]
This form resets the current branch head to <commit> and possibly updates the index (resetting it to the tree of <commit>) and the working tree depending on <mode>, which must be one of the following:
   -q, --quiet           be quiet, only report errors
   --mixed               reset HEAD and index
   --soft                reset only HEAD
   --hard                reset HEAD, index and working tree
   --merge               reset HEAD, index and working tree
   --keep                reset HEAD but keep local changes
   -p, --patch           select hunks interactively

commit changed:
before push the added change to git, you should commit it
git commit -m [message]

You may want to keep current snapshot and also keep going, branch it
git branch [new_branch_name] : create local branch
git branch [new_branch_name] [from_branch_name] : create branch [new_branch_name] from branch [from_branch_name]
git branch -d [branch_name] : delete branch
git checkout [branch_name] : switch to branch
git branch : show all branchs and currently working branch

after a branch created and switched to it,
you can add/delete/modify files and add - commit - push as usual
for example,

git checkout [branch_name]
git touch test
git add test
git commit -m 'test branch'
git push origin [branch_name]

push to Github
git push origin master

Saturday, December 17, 2011

ZK Macro Component practice - togglebutton


<?component name="togglebutton" macroURI="/togglebutton.zul"
    <togglebutton onCheck="alert(self.isChecked());" checked="true"
        enableImage="img/star_fullfill.png" />
    <togglebutton onCheck="alert(self.isChecked());" checked="false"
        enableImage="img/star_fullfill.png" />


<window style="display: inline-block;">
    <checkbox id="mc_togglebutton_checkbox" visible="false" />
    <image id="mc_togglebutton_image" src="img/battery.gif" />

package com;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.HtmlMacroComponent;
import org.zkoss.zk.ui.event.CheckEvent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Image;

public class ToggleButton extends HtmlMacroComponent {
    private Image _img;
    private boolean _checked = true;
    private String _disableImage;
    private String _enableImage;
    public void afterCompose() {

    private void init() {
        // this macro togglebutton
        final Component toggleButton = this;
        _img = (Image) getFirstChild().getFellow("mc_togglebutton_image");
        if (_checked)

        final Image img = _img;
        img.addEventListener(Events.ON_CLICK, new EventListener(){
            public void onEvent(Event event) throws Exception {
                _checked = !_checked;
                if (_checked)
                // create an onCheck event then post it back
                CheckEvent evt = new CheckEvent(Events.ON_CHECK, toggleButton, _checked);
    public void setChecked(boolean checked) {
        _checked = checked;
    public boolean isChecked() {
        return _checked;
    public void setDisableImage(String disableImage) {
        _disableImage = disableImage;
        if (_img != null && !_checked)
    public void setEnableImage(String enableImage) {
        _enableImage = enableImage;
        if (_img != null && _checked)
    public String getDisableImage() {
        return _disableImage;
    public String getEnableImage() {
        return _enableImage;




The project architecture:

The project is available on github