原文最新更新: 23-Apr-2008 16:08:38 UTC
翻译时间:2008年5月3日,王旭 (gnawux<at>gmail.com)
原文链接:http://www.kernel.org/pub/software/scm/git/docs/everyday.html
[基本仓库]: 拥有 GIT 仓库的人需要的命令——也就是所有人,因为 git 的每个工作拷贝都是一个仓库。
之后,[个人开发者 (独立工作)]: 任何需要进行 commit 的人都需要的命令,即使是一个人工作的情况。
如果你和其他人一起工作,你还需要列在[个人开发者 (参与者)]小节的命令。
扮演[集成者]角色的人还需要学习这一节中的命令。
[仓库管理]命令是给哪些负责维护 GIT 仓库的系统管理员的。
所有人都可以用这些命令来维护 git 仓库。
$ git fsck (1)$ git count-objects (2)$ git gc (3)
$ git gc (1)
独立工作的个人开发者不需要和其他人交换补丁,在单一的仓库中独自工作,通常会用到这些命令。
$ 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)
$ 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)
在一个小组中参与协同工作的开发者需要学会下面一些命令,以和他人沟通,同时也需要独立的开发者们会用到的命令。
$ git clone git://git.kernel.org/pub/scm/…/torvalds/linux-2.6 my2.6$ 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)
satellite$ git clone mothership:frotz frotz (1)satellite$ cd frotzsatellite$ git config –get-regexp ‘^(remote|branch).’ (2)remote.origin.url mothership:frotzremote.origin.fetch refs/heads/*:refs/remotes/origin/*branch.master.remote originbranch.master.merge refs/heads/mastersatellite$ git config remote.origin.pushmaster:refs/remotes/satellite/master (3)satellite$ edit/compile/test/commitsatellite$ git push origin (4)mothership$ cd frotzmothership$ git checkout mastermothership$ git merge satellite/master (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)
项目中的中心人物会扮演一个集成者的角色,收集他人提供的变更,查看并集成在一起,对外发布结果。与一般参与者相比,集成者还需要用到这样一些命令。
$ 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)
$ 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 的输出中, master 应该包含 ko-master 的所有内容, 而 next 应该包含ko-next 的所有内容。
仓库管理员会使用如下工具来设置和维护开发者们对仓库的访问方法。
update hook howto 有一个不错的关于管理一个共享的中心仓库的例子。
$ grep 9418 /etc/servicesgit 9418/tcp # Git Version Control System
$ grep git /etc/inetd.confgit stream tcp nowait nobody/usr/bin/git-daemon git-daemon –inetd –export-all /pub/scm
实际配置文件中应该是一行。
$ cat /etc/xinetd.d/git-daemon# default: off# description: The git server offers access to git repositoriesservice git{disable = notype = UNLISTEDport = 9418socket_type = streamwait = nouser = nobodyserver = /usr/bin/git-daemonserver_args = –inetd –export-all –base-path=/pub/scmlog_on_failure += USERID}
设置时请参考你的 xinetd(8) 文档,上述设置适用于 Fedora 系统。其他系统可能有所不同。
$ grep git /etc/passwd (1)alice:x:1000:1000::/home/alice:/usr/bin/git-shellbob:x:1001:1001::/home/bob:/usr/bin/git-shellcindy:x:1002:1002::/home/cindy:/usr/bin/git-shelldavid:x:1003:1003::/home/david:/usr/bin/git-shell$ grep git /etc/shells (2)/usr/bin/git-shell
$ 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/masterdrwxrwsr-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 descriptiondrwxrwsr-x 2 david git 4096 Dec 4 22:40 hooks-rw-rw-r– 1 david git 37504 Dec 4 22:40 indexdrwxrwsr-x 2 david git 4096 Dec 4 22:40 infodrwxrwsr-x 4 david git 4096 Dec 4 22:40 objectsdrwxrwsr-x 4 david git 4096 Nov 7 14:58 refsdrwxrwsr-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|cindyrefs/heads/doc-update bobrefs/tags/v[0-9]* david
dev$ git update-server-info (1)dev$ ftp user@isp.example.com (2)ftp> cp -r .git /home/user/myproject.git
联系客服