Submitted by 404
on Tue, 2008-06-03 16:52
** 我現在常用的git命令
實際例子
進入檔案夾,裡面是我要版本控制的檔案
404:~/project/feh$ git init
Initialized empty Git repository in .git/
建立了一個新的git庫
404:~/project/feh$ git add AUTHORS README TODO
我把3個檔案加入到那個庫裡。如果你想把目前的目錄下所有檔案都加入,直接 git add . 最後那個英文句號表示目前的目錄
404:~/project/feh$ vim TODO
隨便找個檔案做了修改
404:~/project/feh$ git commit -a
修改好後用 commit -a 提交修改 -a是all的意思,讓git自己去找我修改了哪些檔案吧。
這時會有個
# Please enter the commit message for your changes.
# (Comment lines starting with '#' will not be included)
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: AUTHORS
# new file: README
# new file: TODO
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# COPYING
# feh-1.3.4.tar.gz
# feh-1.3.4/
這是讓你寫點你都做了什麼修改。git會預設讓你用vim編輯這個檔案。vim中按i進入編輯模式。按Esc進入命令模式。有什麼不多就多按幾下Esc。然後:w存檔。然後:q,退出。你隨便做個修改,一般我是把這次更新的檔案前面#刪除。存檔退出後,
reated initial commit c1040c1: new file: AUTHORS
3 files changed, 96 insertions(+), 0 deletions(-)
create mode 100644 AUTHORS
create mode 100644 README
create mode 100644 TODO
如果你不寫commit mesage,git會退出提交。這點開始讓我浪費了好多時間,摸不著頭腦為什麼不提交。其實提示寫的明白。所以隨便寫點設呢麼。
fatal: no commit message? aborting commit.
以後每次修改檔案,甚至刪除了檔案,直接git commit -a 就是提交全部(all)了。如果有新檔案件要提交,用 git add 再來一個檔案吧.txt 就好了。隨便變更檔名,git自動聰明地處理好。
在任何一個檔案夾中都可以用上述方法!太方便了!
如何把本地的git庫推到遠端伺服器的庫中。
比如我剛提交了一個w3m文檔翻譯
Push url: git@gitorious.org:w3m-zh/mainline.git More info…
You can run "git push git@gitorious.org:w3m-zh/mainline.git", or you can setup a remote by doing the following:
git remote add origin git@gitorious.org:w3m-zh/mainline.git
to push the master branch to the origin remote we added above:
git push origin master
after that you can just do:
git push
看明白了麼。很簡單。日後提交到本地庫後只要git push就好了。
這些只花了我1個小時時間
就能開動幹活了。而且是長期受益。一直享用版本控制來協助翻譯和寫作。
svn我幾次折騰了幾個小時都沒成功。關鍵還不是入門難度,是git的功能啊~!! :)