這些命令分四種類型:①不需要和其他開發者協作的獨立開發者,會經常用到 git init、git show branch、git commit 等命令;②需要和其他人協作的開發者,會常用到 git clone、git push、git pull、git format patch 。③在項目中負責接收其他開發者發來更新的核心開發者,會常用到 git am、git pull、git format patch、git revert、git push;④ 代碼倉庫管理員常用 git daemon、git shell……
對於任何想做提交的人來說,甚至對於某位單獨工作的人來說,【個人開發者(單獨開發)】部分命令都是必不可少的。如果你和別人一起工作,你也會需要【個人開發者(參與者)】部分列出的命令。
除了上述的部分,擔當【集成人員】角色的人需要知道更多命令。【代碼庫管理】命令幫助系統管理員負責管理,及向git代碼庫提交內容。
單獨的個人開發者不會與他人交換修補程序,只用到下列命令,獨自在單獨的代碼庫上工作:
1 2 3 4 5 6 | $ tar zxf frotz.tar.gz $ cd frotz $ git init $ git add . <1> $ git commit -m "import of frotz source tree." $ git tag v2.43 <2> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | $ git checkout -b alsa-audio <1> $ edit/compile/test $ git checkout -- curses/ux_audio_oss.c <2> $ git add curses/ux_audio_alsa.c <3> $ edit/compile/test $ git diff HEAD <4> $ git commit -a -s <5> $ edit/compile/test $ git reset --soft HEAD^ <6> $ edit/compile/test $ git diff ORIG_HEAD <7> $ git commit -a -c ORIG_HEAD <8> $ git checkout master <9> $ git merge alsa-audio <10> $ git log --since='3 days ago' <11> $ git log v2.43.. curses/ <12> |
作為在一個團體項目里參與角色的開發人員,需要學習如何與他人溝通,除了那些單獨開發者需要掌握的命令以外,還要使用這些命令。
1 | $ git clone git://git.kernel.org/pub/scm/.../torvalds/linux-2.6 my2.6 |
1 2 3 4 5 6 7 8 9 | $ cd my2.6 $ edit/compile/test; git commit -a -s <1> $ git format-patch origin <2> $ git pull <3> $ git log -p ORIG_HEAD.. arch/i386 include/asm-i386 <4> $ git pull git://git.kernel.org/pub/.../jgarzik/libata-dev.git ALL <5> $ git reset --hard ORIG_HEAD <6> $ git gc <7> $ git fetch --tags <8> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | satellite$ git clone mothership:frotz frotz <1> satellite$ cd frotz satellite$ git config --get-regexp '^(remote|branch)\.' <2> remote.origin.url mothership:frotz remote.origin.fetch refs/heads/*:refs/remotes/origin/* branch.master.remote origin branch.master.merge refs/heads/master satellite$ git config remote.origin.push \ master:refs/remotes/satellite/master <3> satellite$ edit/compile/test/commit satellite$ git push origin <4> mothership$ cd frotz mothership$ git checkout master mothership$ git merge satellite/master <5> |
1 2 3 4 5 | $ git checkout -b private2.6.14 v2.6.14 <1> $ edit/compile/test; git commit -a $ git checkout master $ git format-patch -k -m --stdout v2.6.14..private2.6.14 | git am -3 -k <2> |
在一個團隊項目中擔任集成者的是一名相當重要的人員,他接受別人的修改,評審並且集成並且發布結果,供他人使用;除了那些參與者需要的命令之外,還會使用這些命令。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | $ git status <1> $ git show-branch <2> $ mailx <3> s 2 3 4 5 ./+to-apply s 7 8 ./+hold-linus q $ git checkout -b topic/one master $ git am -3 -i -s -u ./+to-apply <4> $ compile/test $ git checkout -b hold/linus && git am -3 -i -s -u ./+hold-linus <5> $ git checkout topic/one && git rebase master <6> $ git checkout pu && git reset --hard next <7> $ git merge topic/one topic/two && git merge hold/linus <8> $ git checkout maint $ git cherry-pick master~4 <9> $ compile/test $ git tag -s -m "GIT 0.99.9x" v0.99.9x <10> $ git fetch ko && git show-branch master maint 'tags/ko-*' <11> $ git push ko <12> $ git push ko v0.99.9x <13> |
1 2 3 4 5 6 7 8 9 | $ cat .git/remotes/ko URL: kernel.org:/pub/scm/git/git.git Pull: master:refs/tags/ko-master Pull: next:refs/tags/ko-next Pull: maint:refs/tags/ko-maint Push: master Push: next Push: +pu Push: maint |
在從git show-branch的輸出里,主分支應該有所有ko-master有的,並且next應該有ko-next有的所有內容。
代碼庫管理員使用下列工具來設置及維護開發者對代碼庫的訪問。
update hook howto有一個很好的管理共享中央代碼庫的實例。
1 2 | $ grep 9418 /etc/services git 9418/tcp # Git Version Control System |
從inetd運行git-daemon來服務於/pub/scm
$ grep git /etc/inetd.conf git stream tcp nowait nobody \ /usr/bin/git-daemon git-daemon --inetd --export-all /pub/scm
實際的配置應該在1行里。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $ cat /etc/xinetd.d/git-daemon # default: off # description: The git server offers access to git repositories service git { disable = no type = UNLISTED port = 9418 socket_type = stream wait = no user = nobody server = /usr/bin/git-daemon server_args = --inetd --export-all --base-path=/pub/scm log_on_failure += USERID } |
檢查xinetd(8)文檔並設置,這個文檔來自於Fedora系統。其他也許會不一樣。
授予開發者只推/拉訪問操作許可權。
$ grep git /etc/passwd <1> alice:x:1000:1000::/home/alice:/usr/bin/git-shell bob:x:1001:1001::/home/bob:/usr/bin/git-shell cindy:x:1002:1002::/home/cindy:/usr/bin/git-shell david:x:1003:1003::/home/david:/usr/bin/git-shell $ grep git /etc/shells <2> /usr/bin/git-shell
CVS風格的共享代碼庫
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | $ grep git /etc/group <1> git:x:9418:alice,bob,cindy,david $ cd /home/devo.git $ ls -l <2> lrwxrwxrwx 1 david git 17 Dec 4 22:40 HEAD -> refs/heads/master drwxrwsr-x 2 david git 4096 Dec 4 22:40 branches -rw-rw-r-- 1 david git 84 Dec 4 22:40 config -rw-rw-r-- 1 david git 58 Dec 4 22:40 description drwxrwsr-x 2 david git 4096 Dec 4 22:40 hooks -rw-rw-r-- 1 david git 37504 Dec 4 22:40 index drwxrwsr-x 2 david git 4096 Dec 4 22:40 info drwxrwsr-x 4 david git 4096 Dec 4 22:40 objects drwxrwsr-x 4 david git 4096 Nov 7 14:58 refs drwxrwsr-x 2 david git 4096 Dec 4 22:40 remotes $ ls -l hooks/update <3> -r-xr-xr-x 1 david git 3536 Dec 4 22:40 update $ cat info/allowed-users <4> refs/heads/master alice\|cindy refs/heads/doc-update bob refs/tags/v[0-9]* david |
支持dumb協議傳送的HTTP伺服器
1 2 3 | dev$ git update-server-info <1> dev$ ftp user@isp.example.com <2> ftp> cp -r .git /home/user/myproject.git |
原文鏈接: kernel.org 翻譯: 伯樂在線 - cjpan
[火星人 ] 開發者日常使用的 Git 命令已經有832次圍觀