Fork me on GitHub
Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

5/13/2013

Git alias problem

Recently, don't know why, I found the git aliasing does not work. When I use git st aliasing command, I got below error:

fatal: cannot exec 'git-st': Not a directory
Problem is /usr/bin/python is not directed to directory

After search for a while, I found it should be caused by my environment variable PATH.

Use the command echo $PATH |tr ':' '\n' |xargs ls -ld, I found there is a symbolic link in the list /usr/bin/python -> python2.7 If it is removed, the git aliasing problem is gone.

I think it should be noticed that the environment path should points to directories not to files.

[~]$ echo $PATH |tr ':' '\n' |xargs ls -ld

drwxr-xr-x 2 root      root         4096 Apr 17 09:52 /bin
drwxrwxr-x 2 brownylin brownylin    4096 Apr 25 09:41 /home/brownylin/Java/maven3/bin
drwxr-xr-x 2 root      root        40960 May  9 13:07 /usr/bin
lrwxrwxrwx 1 root      root            9 Apr 15 15:54 /usr/bin/python -> python2.7
drwxr-xr-x 2 root      root         4096 Apr 24 11:34 /usr/local/bin


References

Git alias problem
http://stackoverflow.com/questions/4019501/git-alias-problem

2/09/2012

[Git] How to combine multiple commits to only one patch

one commit for one goal 是一個好習慣,不過往往會在 local branch 新增許多 commits。等到 feature 完成,有時候會希望可以將這些 commits 全部整理成一個 patch,方便 forward 給別人 或是 apply 回 master branch,這時該怎麼做呢?

假設你從 branch master checkout 一出一個 branch feature 做開發,然後在 branch feature 上面提交了一些 commits。現在你希望將這些 commits 弄成一個單一的 patch,然後 apply 到 branch master 上面。

首先,先回到 branch master,建立一個跟 master 一樣的 temp branch tmpsquash

git checkout -b tmpsquash

在 branch tmpsquash 上以 --squash 的方式 merge 到 branch feature

git merge --squash feature

於是你就會看到,branch feature 那些 commits 的內容全變成了 branch tmpsquash 的 diff。這時候你就可以把它弄成一個 commit。

git commit -a -m "My squashed commits"

最後,將他打包成一個 patch

git format-patch master

Reference

  1. How do you squash commits into one patch with git format-patch?

-- EOF --

12/30/2011

Using Git In Non Merging Way

Here is the flow I used in the past few months development wit Git

  1. First, create a branch 'base' to track the remote collaborating branch

    $ git checkout -b base -t origin/trunk
        // create a local branch 'base' to track a remote branch 'origin/trunk'
    $ git branch -a
        // show the detail info about local/remote branches
    $ git remote show origin
        // to know which local branch tracks which remote branch, see the bottom of output
    
  2. Any feature/hotfix are checkout to a separate feature branch from base branch, and develop on it

    $ git checkout -b 1201-fea
        // create a local branch for development
    
  3. After completing and verifying your changes, patch your changes

    $ git diff > p1225_refactor
        // output your changes to a patch file names 'p1201_fea'
    
  4. When ready to sync changes to server, update your base branch, checkout to it, then apply your patch

    $ git checkout base
    $ git pull --rebase
        // make sure the branch in the updated condition
    $ git apply p1225_refactor
        // apply your changes on top of it
    
  5. The habits which prevent you from the regular loop of conflict and merge

    Often update your 'base' branch, don't let it lag too much behind the remote trunk

    If your changes are not urgent, keep checking out a daily experiment branch from 'base' and try to apply your patch and verify it. If any conflict, you can fix it as early as posiible

    Naming your branches and patches clearly, give them some identifiable prefix or suffix

-- EOF --

3/18/2011

[Git] 常用 git 指令筆記

1. Untrack files in git (當你不想要追蹤某個檔案,但是卻又不希望把它從資料夾刪除的時候使用)
git rm --cached filename

2. 切換 branch 時候,有東西沒有 commit 無法切換
先 git stash -> 切換 branch -> 切回來的時候再用 git stash pop
參考:http://ihower.tw/blog/archives/2620