-
Version Control System
查看git版本和命令帮助
$ git –version
git version 1.7.1
$ git log –help
$ git help log
-
Set up git
设置自己的名字和邮箱
$ git config –global user.name “Scott Chacon”
$ git config –global user.email “schacon@gmail.com”
设置文本编辑器
$ git config –global core.editor ’emacs’
-
Initializing a new git repo
创建一个文件夹并初始化
$ rails myproject
$ cd myproject
$ git init
提交第一个版本的文件
$ git add .
$ git commit -m ‘initial commit
查看log
$ git log
commit eac2f939e6a1cb3189fedd19919888d998ab0431
Author: Scott Chacon <schacon@gmail.com>
Date: Sun Feb 8 07:55:57 2009 -0800
initial commit
-
Cloning a git repo
将github网站上的repo下载到本地
$ git clone git://github.com/schacon/munger.git
$ cd munger
$ ls
README examples munger.gemspec
Rakefile lib spec
也可以通过http的方式
$ git clone http://github.com/schacon/munger.git
-
Using the staging area
查看当前目录的repo状态
$ git status
# On branch master
# Changed but not updated:
# (use “git add <file>…” to update what will be committed)
# (use “git checkout — <file>…” to discard changes in working directory)
#
# modified: README
# modified: lib/simplegit.rb
#
no changes added to commit (use “git add” and/or “git commit -a”)
stage一个文件,准备提交
$ git add README
$ git status
# On branch master
# Changes to be committed:
# (use “git reset HEAD <file>…” to unstage)
#
# modified: README
#
# Changed but not updated:
# (use “git add <file>…” to update what will be committed)
# (use “git checkout — <file>…” to discard changes in working directory)
#
# modified: lib/simplegit.rb
提交刚才staged的文件
$ git commit -m ‘updated the README’
[master]: created 14bb3c6: “updated the README”
1 files changed, 1 insertions(+), 2 deletions(-)
Stage另一个文件并且提交
$ git commit -a -m ‘added a staging command to the library’
[master]: created bbaee85: “added a staging command to the library”
1 files changed, 4 insertions(+), 0 deletions(-)
$ git status
# On branch master
# Your branch is ahead of ‘origin/master’ by 2 commits.
#
nothing to commit (working directory clean)
在stage之前,查看改动,所以这之前要先把其他的文件staged。
$ git diff
diff –git a/lib/simplegit.rb b/lib/simplegit.rb
index dd5ecc4..8ac6604 100644
— a/lib/simplegit.rb
+++ b/lib/simplegit.rb
@@ -25,6 +25,10 @@ class SimpleGit
command(“git log -n 25 #{treeish}”)
end
+ def log_single(branch = ‘master’)
+ command(“git log –pretty=oneline #{branch}”)
+ end
+
def blame(path)
command(“git blame #{path}”)
end
查看已经staged的文件的改动不同
$ git diff –staged
diff –git a/README b/README
index c526f88..879f0d4 100644
— a/README
+++ b/README
@@ -8,3 +8,4 @@ It is an example for the Git Peepcode book that I’m currently writin
Author : Scott Chacon (schacon@gmail.com)
Orange Peel Chacon (opchacon@gmail.com)
Magnus O. Chacon (mchacon@gmail.com)
+ Josephine Chacon (jo.chacon@gmail.com)
发表回复