2017年2月16日 星期四

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

2013年11月5日 星期二

看某一個 commit 的 diff

只要看某一個 commit 的 diff,就用
$ git show 2e6f1155dd56512d5f848f4b7e6198c38aa256f2

2013年8月12日 星期一

git with https source.. SSL error

最近越來越多 git source 採用 https,

有兩個麻煩的地方:
  • username, password
  • SSL certification
usename, password 就用 ~/.netrc 就可以,
把 machine, login, password 寫進去:
machine my.git.com
login checko
password mygitpassword
.. 對,是明文 ..

site SSL certification fail 就會出現...
Initialized empty Git repository in /xxxx/xxxx/.git/
Password: 
error: server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt 
CRLfile: none while accessing https://xxxx@xxxx.xxxx/xxxx/xxxx.git/info/refs

fatal: HTTP request failed
這時候就加上這個還就可以:
export GIT_SSL_NO_VERIFY=1


2013年7月22日 星期一

git difftool readonly

某一天突然 run git difftool 變成以 readonly 開啟。
把另一個系統的 git (1.7.5) copy 到 local 的 ~/bin/ 下,結果一樣。

所以只好用 apt-get purge git 和 apt-get autoremove 把 git 清掉。
然後 再 apt-get install git

把 git 裝回來(結果是 1.7.1) 。
就 OK 了。

結果 android repo 需要 1.7.2...

設法 安裝 1.7.2 以上...(結果裝到 1.8.3.4)
git difftool 又是 read-only...

後來發現vim 打開雖然是 RO,但是寫入時加上強制 '!' 符號,還是可以寫入


其實只要在 .vimrc 下,增加一個option:
:set noro
就可以了..