2014年11月17日 星期一

hard reset to --- 放棄掉.....

ref: http://stackoverflow.com/questions/4114095/revert-to-a-previous-git-commit

如果是自己的 git,沒有跟人家 sync..(或是還沒sync).
那就可以用 ...
git reset --hard ed2b7f3501f6
這樣,用 git log 看,最後會在 commit ed2b7f3501f6 的地方。
這個 commit 後面的都不見了,,

2014年5月6日 星期二

commit and checkpatch.pl and hooks

checkpatch.pl 是一個 perl script。
越來檢查有沒有符合該專案的 coding style.

所以可以叫 git commit 時,自動 run 這個 script。
防止不合style 的 code 被 commit 進 source code

這個動作通常是放在 git 的 hooks 裡:
 .git/hooks/prepare-commit-msg

這個 hooks 是一個 shell script,在 git commit 時,書入完 commit 時會被執行。

所以可以這樣寫:
#!/bin/sh
if test -r "checkpatch.pl"; then
  git diff --cached | ./checkpatch.pl --no-signoff --no-tree -
fi
檢查project 目錄是不是有 checkpatch.pl 好決定是不是要 執行

這樣改完後,如果 checkpatch.pl 結果是 warning 或 error, commit 就不會進行 commit

這個 script 也可以吃參數,$1 就是 commit comment。
所以可以利用 commit comment 來控制他的動作。
例如:
 ! grep -qs "\[NO_STYLE_CHECK\]" "$1" || exit 0
就可以在 commit 時,加入 "[NO_STYLE_CHECK]" bypass 掉 checkpatch:
$ git commit -am "[NO_STYLE_CHECK] try commit dirty codes"


ref:
  • http://blog.bartoszmajsak.com/blog/2012/11/07/lazy-developers-toolbox-number-1-prepend-git-commit-messages/
  • https://answers.atlassian.com/questions/169399/sourcetree-and-git-prepare-commit-msg
  • http://www.fluff.org/ben/linux/githooks/pre-commit

#!/bin/sh
#
# pre-commit hook to run check-patch on the output and stop any commits
# that do not pass. Note, only for git-commit, and not for any of the
# other scenarios
#
# Copyright 2010 Ben Dooks, 

if git rev-parse --verify HEAD 2>/dev/null >/dev/null
then
 against=HEAD
else
 # Initial commit: diff against an empty tree object
 against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

git diff --cached $against -- | ./scripts/checkpatch.pl --no-signoff -

2014年2月20日 星期四

revert 某個 commit..

有時候想把某個 commit 消除。
要作 :
$ git revert COMMIT-SHA

然後就會出現 comment editor 要你confirm,

這個動作不會把那個 commit 從 commit log 中拿掉,
而是產生一個相反動作的 commit, 把那個 commit 消除。

所以 revert 完是可以 push 到 remote server 的。



所以要把最新的 3 個 commit 都 revert 的話:
git log
commit A
 ...
commit B
 ...
commit C
..
就要反過來:
 git revert A
 git revert B
 git revert C