2012年10月30日 星期二

command cheat sheet


How to mkdir only if a dir does not already exist

reference url:
http://stackoverflow.com/questions/793858/how-to-mkdir-only-if-a-dir-does-not-already-exist

Try mkdir -p:
mkdir -p foo
Note that this will also create any intermediate directories that don't exist; for instance,
mkdir -p foo/bar/baz
will create directories foo, foo/bar, and foo/bar/baz if they don't exist.

比較不同電腦資料夾差異

rsync compare

rsync -rvnc --delete website/ laptop:projects/website/
 
 
man rsync|grep -e ' -n'
-n, --dry-run               perform a trial run with no changes made 

http://psung.blogspot.tw/2008/06/comparing-directory-trees-with-diff-or.html

2012年10月25日 星期四

git note


git rename branch
http://fredchiu.wordpress.com/2011/12/28/%E9%87%8D%E6%96%B0%E5%91%BD%E5%90%8D-rename-git-branch/
假設現在有兩個 branch, master 跟 old-branch ,目前在 master ,想要把 old-branch 的名字改成 new-branch 的話,請輸入:
git branch -m old-branch new-branch
如果現在已經在 old-branch ,想要直接把名字改成 new-branch 的話,就輸入:
git branch -m new-branch

git orphan
http://stackoverflow.com/questions/5086833/how-to-create-a-branch-without-adding-all-the-existing-files
git checkout --orphan branchname
git rm -rf .
After doing that you can create, add, and commit new files and the resulting branch will have no common history with any other branches in your project (unless you merge them at some point).

git untrack
http://source.kohlerville.com/2009/02/untrack-files-in-git/
The following command will stop tracking but keep the file there intact.
git rm --cached filename

git clone local
http://stackoverflow.com/questions/2519933/git-clone-repo-across-local-file-system
C:\some\dir\> git clone --local file:///C:/path/to/repo my_project

git stat
http://blog.longwin.com.tw/2009/05/git-learn-initial-command-2009/
不小心修改到檔案,但卻不知道改到哪些檔案,與最後的 commit 比較,顯示修改過的檔案清單,請輸入以下指令
git diff --stat

命令列模式顯示 tree
git log --graph --oneline --all

Cherry picking a range of commits
http://ariejan.net/2010/06/10/cherry-picking-specific-commits-from-another-branch
In some cases picking one single commit is not enough. You need, let's say three consecutive commits. cherry-pick is not the right tool for this. rebase is. From the previous example, you'd want commit 76cada and 62ecb3 in master.
The flow is to first create a new branch from feature at the last commit you want, in this case 62ecb3.
git checkout -b newbranch 62ecb3
Next up, you rebase the newbranch commit --onto master. The 76cada^ indicates that you want to start from that specific commit.
git rebase --onto master 76cada^
The result is that commits 76cada through 62ecb3 are applied to master.

強制更改 server 上的 branch 舊有的提交歷史,指定將 server 上特定 branch ( e.g. develop)的提交歷史紀錄,強制覆寫為本機 branch ( e.g. develop)的提交歷史紀錄
需具備該權限,才能正常執行操作
git push origin develop -f

恢復 Commit,重新提交 Commit

假如今天您修改了兩個檔案,並且新增到暫存區了,狀態如下:
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   Makefile
#       modified:   user/easy_setup/easysetup.h
#
並且已經執行了 git commit -m “first commit”,發現訊息寫錯想要修改,可以透過 reset 方式來做,請先用 git log 方式查看訊息
git log --stat
commit c13eb41110a38ef7145bb8815560641697800659
Author: appleboy <appleboy.tw at gmail.com>
Date:   Fri Aug 20 20:02:55 2010 +0800

    first commit

 Makefile                    |   10 ++-
 user/easy_setup/easysetup.h |  157 ++++++++++++++++++++-----------------------
 2 files changed, 79 insertions(+), 88 deletions(-)
這要怎麼解決才可以改變此訊息呢?
git reset --soft HEAD^
這是一個大家常用的作法,假如您想要修改 commit 訊息,或者是尚未修改好檔案,下完此指令,您會發現 reset 會幫忙把舊的 head 複製到 .git/ORIG_HEAD,如果您沒有想要重新建立 commit 訊息,您可以下
git commit -a -c ORIG_HEAD
git 會跳出剛剛的 first commit 讓您來修改,或者是自己用 git commit -m “XXXXXXX” 這樣也可以喔。

取消最後一次 commit ,提交紀錄及檔案都還原成倒數第二次 commit 的狀態

強制恢復到上一版本

上面是介紹恢復 commit 訊息,之前修改過的檔案還會存在,底下會使用 reset hard 的方式恢復到上一版本,上一版本跟此版本之間所修改的檔案,將不會存檔,git reset 參數之一 –hard
git reset --hard HEAD~3
這指令意思是說,最後三個版本 (HEAD, HEAD^, and HEAD~2) 都不是您想要修改的,你也不想給其他人看見這三個版本資訊,如果您想要保存修改過的檔案,請勿下此指令
摘錄自以下網址:
http://blog.wu-boy.com/2010/08/git-%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6%EF%BC%9A%E5%88%A9%E7%94%A8-git-reset-%E6%81%A2%E5%BE%A9%E6%AA%94%E6%A1%88%E3%80%81%E6%9A%AB%E5%AD%98%E7%8B%80%E6%85%8B%E3%80%81commit-%E8%A8%8A%E6%81%AF/

如何徹底刪除 Git 中的提交(commit)
http://liuhui998.com/2010/11/06/remove_commits_completely/
git reflog expire --expire-unreachable=0 --all
git gc --prune=0

git whatchanged 可以列出比 git log 更詳細的修改列表:

運行git log:
$ git log
commit 41b3d1cfaae0184bb8e5f27a165d51cc23867413
Author: git-tester
Date: Mon Nov 17 15:28:01 2008 +0800
master:002
commit 2d89602d0c9955824df0d2c023e447f5d98d863a
Author: git-tester
Date: Mon Nov 17 15:26:40 2008 +0800
master:001
我們能夠看到的信息有commit,author,date,commit message,但是卻不知道這次提交涉及到那些文件。
運行 git whatchanged
$ git whatchanged
commit 41b3d1cfaae0184bb8e5f27a165d51cc23867413
Author: git-tester
Date: Mon Nov 17 15:28:01 2008 +0800
master:002
:000000 100644 0000000… fe58238… A file1
:000000 100644 0000000… fe31ac6… A file2
:000000 100644 0000000… 3b40a58… M file3
:000000 100644 0000000… bdabb41… D file4
commit 2d89602d0c9955824df0d2c023e447f5d98d863a
Author: git-tester
Date: Mon Nov 17 15:26:40 2008 +0800
master:001
:000000 100644 0000000… fe58238… A file1
:000000 100644 0000000… fe31ac6… A file2
:000000 100644 0000000… 3b40a58… A file3
:000000 100644 0000000… bdabb41… A file4
可以看到提交涉及到的文件,A — add, M — modify, D — delete
資料來源網址:
http://blog.microsuncn.com/?p=2011

顯示目前分支名
git rev-parse --abbrev-ref HEAD

git 跨平台協作,換行符號設定
git config --global core.autocrlf input# Set this setting on OSX or Linux

git config --global core.autocrlf true# Set this setting on Windows 
參考資料來源:
https://help.github.com/articles/dealing-with-line-endings
http://www.kernel.org/pub/software/scm/git/docs/git-config.html
 
從 git status 取得工作目錄中有修改過檔案清單 
git status -s|egrep -v '^ D'|egrep -o '^ M.*'|egrep -o 'M .*'|egrep -o ' .*'|egrep -o '[^[:space:]].*'
 


git 命令列模式顯示 git tree


網址:
http://stackoverflow.com/questions/1527234/finding-a-branch-point-with-git

摘錄:
git log --graph --oneline --all
which shows (assuming git config --global color.ui auto):
enter image description here
Or, in straight text:

*   a9546a2 merge from topic back to master
|\  
| *   648ca35 merging master onto topic
| |\  
| * | 132ee2a first commit on topic branch
* | | e7c863d commit on master after master was merged to topic
| |/  
|/|   
* | 37ad159 post-branch commit on master
|/  
* 6aafd7f second commit on master before branching
* 4112403 initial commit on master

透過命令列修改螢幕解析度


關鍵字:
cli change resolution

網址:
http://superuser.com/questions/89302/any-way-of-changing-windows-7-screen-resolution-via-command-line

摘錄:
Use QRes.exe then say,
QRes.exe /x:800 /y:600

2012年10月8日 星期一

file archive unarchive


file archive(cli OR command)example

http://www.computerhope.com/unix/utar.htm

摘錄:
Creating a tar file:
tar -cvwf file.tar myfile.txt
In the above example, the system would create a tar named file.tar in the directory you currently are in. Wildcards could also be used in this command, for example: tar -cvwf file.tar *.txt would archive all txt files in the current directory.
tar -cvwf home.tar home/
tar -cvf lampp.tar /opt/lampp/
In the above example command the system would create a tar file named home.tar containing the home directory and place that file in the current directory.

unarchive
tar xvf htdocs.tar

http://www.linuxquestions.org/questions/linux-newbie-8/how-to-extract-tgz-125678/
.tgz and tar.gz files are pretty much the same. You extract them like this:
Code:
tar xvzf file.tar.gz
tar xvzf file.tgz

2012年10月6日 星期六

開機執行(command OR script)


http://blog.xuite.net/misgarlic/weblogic/37343210-%E9%96%8B%E6%A9%9F%E4%B9%8B%E5%BE%8C%E5%9F%B7%E8%A1%8C%E6%9F%90%E4%BA%9B+scripts

在 ubuntu 上是要改 /etc/rc.local 這個檔
(1) /etc/rc.local
這個檔案就放一些你想要執行的 command, scripts