引用
commit fa6f27b7de063c2f301b0e7148b5bd5e813faa98 tree 5e7a19c158b89fbc52a078771a833ee839727404 parent 76f31606376180ca88efa12be341dbb14fb06fdf
咋一看,这40位的乱码挺吓人的,但是你了解它的作用就不会被吓到了。 这是object name,是作为你每次提交的信息标识。这是用SHA1加密hash函数根据你的对象的内容算出来的。Git的一些优点: Git通过简单比较object name就可以快速的确定这两个对象是否相等。 因为object name在每个repository里都是以相同的方法来计算的,所以在不同的两个repository的同一个内容都会被存储在相同的object name下。 Git可以在读取对象的时候检查错误,检查该对象的名称是否还是它的内容的SHA1 hash。 The Objects 每个对象都由三个东东组成:type,size,content。size当然是content的size了,而content却是依赖于这个对象是个什么type了。而type又有四类:“blob”,”tree”, “commit”, “tag”。 - blob # 通常被用来存储文件数据,一般是个文件。
- tree # 基本上像个目录结构,比如x / yyy
- commit # 它指向一个单独的tree,它标记了一个时刻的项目的面貌,就像给这个project照了个艳照一样。它包含那个时刻的元信息,例如时间戳,改变本次提交的作者,前一个提交的指向标等等。
- tag # 专门用来指定某些特殊行为的commits。
- git show
- commit cf70117f3cc497fba42890171d29ae404061d25f
- Author: Alex <blackanger.z@gmail.com>
- Date: Sun Dec 7 05:55:46 2008 +0800
- modify .gitignore
- diff --git a/.gitignore b/.gitignore
- index deb5b7c..77573ab 100644
- --- a/.gitignore
- +++ b/.gitignore
- @@ -1,2 +1,2 @@
- -log/
- +/log
- .DS_Store
引用
git ls-tree cf701 100644 blob 77573ab40c4f010c0e050f1bbff2ad3ab78f1428 .gitignore 100644 blob f8cd794a2d06e6c409737d5bcd39a20abb62db26 README 100644 blob 3bb0e8592a41ae3185ee32266c860714980dbed7 Rakefile 040000 tree ee99c7a2e9842acbab05fcd02ec510ea917218b2 app 040000 tree 0aff84690f37df01a7cac96529657222cbeeebf6 config 040000 tree 92aaeee021e9c7da661bac141ab55c17a3ae79ee db 040000 tree 0269300738b048a5cc34769d1436d9f228499018 doc 040000 tree 1e384157d8bc3cd7aab5b0b5605e9a78d0612426 features 040000 tree 9f87e761776449b7d43ea112573f8ae27faaf826 lib 040000 tree 4875662d9a7e07a7b95b68958e518fdd65235124 public 040000 tree 11741373949f86364c10af17db764d1af3bc048f script 040000 tree 20433690c23ae3a299b5a02147f68fdf94820370 spec 040000 tree 646d8b1458d23ba0ec396ef5748205977b023f3f stories 040000 tree cc48cdef8eba2b5333c6a01d5795bb6efb43182f test 040000 tree e85767f4716fd20a53d7d6455972c6ec6571c833 vendor
cf701.。。是上一个tree对象,是整个app的tree对象,熟悉Rails的人就可以看得出来这个tree目录。 请注意这些文件到mode为644或755,以保证git执行时候有足够到权限。 Commit Object 你可以用git show或git log加–pretty=raw参数来检查你的提交,例如: - git show -s --pretty=raw cf701
- commit cf70117f3cc497fba42890171d29ae404061d25f
- tree 6ccb7edcdb14205861feb263a7607b8921c75fa3
- parent 3e794f3e4dcb8d362bfb11464c849070bd04a35f
- author Alex <blackanger.z@gmail.com> 1228600546 +0800
- committer Alex <blackanger.z@gmail.com> 1228600546 +0800
- modify .gitignore
- cd .git
- ~/work/mars/.git>ls
- COMMIT_EDITMSG branches description index logs refs
- HEAD config hooks info objects
- git status
- # On branch master
- nothing to commit (working directory clean)
- $git status
- # On branch master
- # Your branch is behind 'origin/master' by 11 commits, and can be fast-forwarded.
- #
- # Changes to be committed:
- # (use "git reset HEAD <file>..." to unstage)
- #
- # modified: daemon.c
- #
- # Changed but not updated:
- # (use "git add <file>..." to update what will be committed)
- #
- # modified: grep.c
- # modified: grep.h
- #
- # Untracked files:
- # (use "git add <file>..." to include in what will be committed)
- #
- blametree
- blametree-init
- git-gui/git-citool
- $ git config --global user.name "Alex Zhang"
- $ git config --global user.email “blackanger.z@gmail.com"
- git url : git clone git://git.kernel.org/pub/scm/git/git.git
- #或者
- http : git clone http://www.kernel.org/pub/scm/git/git.git
- cd project
- git init
- #则会输出:
- Initialized empty Git repository in .git/
- git commit #你可能需要提交了。
- git commit -a #把新近的改变加到index里顺便提交。
- git branch experimental
- <pre lang="bash" line="1">
- #如果你现在运行:
- <pre lang="bash" line="1">
- git branch
- experimental
- * master
- git checkout experimental
- $ git commit -a
- git branch
- #输出
- * experimental
- master
- $ git checkout master
- git branch
- #输出:
- experimental
- master
- $ git merge next
- 100% (4/4) done
- Auto-merged file.txt
- CONFLICT (content): Merge conflict in file.txt
- Automatic merge failed; fix conflicts and then commit the result.
- $ git add file.txt
- $ git commit
- git log #版本号
- $ git clone /home/alice/project myrepo
- $ git commit -a
- (repeat as necessary)
- $ cd /home/alice/project
- $ git pull /home/bob/myrepo master #(此命令,master参数不是必须的)
- $ git remote add bob /home/bob/myrepo
- $ git fetch bob
- $ git log -p master..bob/master
- $ git merge bob/master
- $ git pull . remotes/bob/master
- $ git pull
- $ git config --get remote.origin.url
- /home/alice/project
- $ git branch -r
- #输出
- origin/master
引用
you push your personal repo ——————> your public repo ^ | | | | you pull | they pull | | | | | they push V their public repo <——————- their repo
Pushing changes to a public repository - $ git push ssh://yourserver.com/~you/proj.git master:master
- #或者是
- $ git push ssh://yourserver.com/~you/proj.git master
- $ cat >>.git/config <<EOF
- [remote "public-repo"]
- url = ssh://yourserver.com/~you/proj.git
- EOF
- $ git push public-repo master
- </pr>
- #以GitHub为例子, 保存在github上的一个项目, 我查看它的config:
- [remote "origin"]
- url = git@github.com:blackanger/mars.git
- fetch = +refs/heads/*:refs/remotes/origin/*
- #这样,我每次往github push代码就是用命令:
- git push origin master
- #详细的可以去看 www.gitcasts.com
- <em><strong>Git Tag</strong></em>
- 1.Lightweight Tags
- ~/work/mars>git tag stable-1 cf701
- ~/work/mars>git show stable-1
- commit cf70117f3cc497fba42890171d29ae404061d25f
- Author: Alex <blackanger.z@gmail.com>
- Date: Sun Dec 7 05:55:46 2008 +0800
- modify .gitignore
- 。。。
- $ git tag -a stable-1 1b2e1d63ff