Thursday, February 24, 2011

[Git] Rebase

So far I have used git rebase for 3 scenarios.
  1. Want to add more change in the commit that is not the last commit of any branch. Use git rebase -i
  2. Want to move whole different branch to base on another branch.
          A---B---C topic
    D---E---F---G master
                  A'--B'--C' topic
    D---E---F---G master
    git checkout <branch-to-move>
    git rebase <base-branch>
  3. Want to move part of different branch to base on another branch.
        o---o---o---o---o  master
    o---o---o---o---o next
    o---o---o topic
    o---o---o---o---o  master
    | \
    | o'--o'--o' topic
    o---o---o---o---o next
    git rebase --onto <new-base-branch> <old-base-branch> <move-branch>

Wednesday, February 23, 2011

[Git] delete/remove remote tag

To delete/remove remote branch in Git, you use
git push <remote*> :<branch-to-remove>

Also to delete/remove tag in remote server, you can use
git push <remote> :refs/tags/<tag-to-remote>

These commands might seem weird and hard to remember. To be able to remember them easier, I suggest you to see this full git push command
git push <remote> <local-branch-name>:<remote-branch-name>

Then to delete is to push empty branch to expected branch on remote. That's all why.

 *remote is an alias of other repository see git remote
Credit: How to: Delete a remote Git tag


The current version of git now support argument --delete for push. So now you can delete branch hello from origin with this command
git push --delete origin hello

Wednesday, February 16, 2011

[Git] Ignore change of a file that is in an index

There is a command git update-index --assume-unchanged <file> for ignore.
And there is a command git update-index --no-assume-unchanged <file> for unignore.

For listing assume-unchanged files use git ls-files -v and see lower h in front of file name.
You can combine this with grep "h ". And you can also use git ls-files -v if you are interesting only a file.

[Git] partially add some changes in a file to index

- Use git add -i (<filename>)
- Select 5 (or p) then enter to see changes for selection.
- Choose files by type number in front of each file name and enter.
- Enter again to start.
- Type y or n to choose or not choose changes.
  Type s to divide changes to smaller sectioin.
  Type e to manually choose change.
- After back to main prompt choose 7 (or q) and enter to leave.

Tuesday, February 8, 2011

Ant OS specific value

<condition property="os.dep.value" value="value for MacOSX">
  <os family="mac" />

<condition property="os.dep.value" value="value for Windows">
  <os family="windows" />

<condition property="os.dep.value" value="value for Unix" >
  <os family="unix" />

Use as "${os.dep.value}"

Creadit: Can I make the Ant copy task OS-specific? - Stack Overflow, How to make a conditional decision in an Ant build script based on operating system | java ant |

Wednesday, February 2, 2011

Generate current Git version in Ant for Hudson

At the time I wrote this blog there is no Git Ant task. Workaround for getting current commit version is to use exec directly invoke git describe as below.
<exec executable="git" outputproperty="build.commit">
    <arg value="describe"/>
    <arg value="--tags"/>
    <arg value="--abbrev=20"/>

Now you can get result value of git describe from ${build.commit}.
Credit: How to lookup the latest git commit hash from an ant build script - Stack Overflow

But there is also some problems with Hudson's git plug-in which it always tags build revision that causes our git describe return the wrong result. There was someone send patch to fix this but this is not build to the plug-in yet. Currently workaround is provided in that patch page, add paramter to git describe, "--match=[^(hudson)]*", to ignore tag from Hudson. So we have to add more arg line to Ant's exec task:
<arg value="--match=[^(hudson)]*">

That's all.

Disable SSH host key checking

I summarized this from Linux Commando: How to disable SSH host key checking

He suggested 3 approaches
  1. $ sed -i 3d ~/.ssh/known_hosts
  2. Use parameters
    * StrictHostKeyCheckin
    * UserKnownHostsFile
    ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no username@hostname
  3. Config file ~/.ssh/config (or /etc/ssh/ssh_config for global) & restart ssh
    Host 192.168.0.*
    StrictHostKeyChecking no

Config number of file descriptors on Linux

Check file descriptor limit for a process. Vary depending on owner of the process $ cat /proc/{process-id}/limits Check current number of...