我現在常用的git命令

來源:互聯網
上載者:User

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的功能啊~!! :)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.