by tangke 2009-10-22
1.git init
git-init和git-init-db命令相同,用于建立一个仓库
$cd example
$git init
$ls
.git
$git --bare init
$ls
hooks refs .............
2.git add
-n 测试能够加入,并不是真正的加入该文件。
tangke@tangke-laptop:~/Test/git-repo$ git add -n *
add 'he.c'
tangke@tangke-laptop:~/Test/git-repo$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: hello.c
#
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# he.c
我们可以尝试加入一个不存在的文件
tangke@tangke-laptop:~/Test/git-repo$ git add -n tagneke.c
fatal: pathspec 'tagneke.c' did not match any files
3.git rm
a.-n 测试是否能够删除某个已经存在于库中的文件或者目录,类似于git add -n
b.-r 允许进行目录递归
c.--cached 删除库中的某个文件或者目录,但是并不删除当前的这个文件或者目录
tangke@tangke-laptop:~/Test/git-repo$ git rm --cached he.c
rm 'he.c'
tangke@tangke-laptop:~/Test/git-repo$ ls
he.c hel.c hell.c hello.c
tangke@tangke-laptop:~/Test/git-repo$ git commit -m "fixed4"
[master e769589] fixed4
1 files changed, 0 insertions(+), 2 deletions(-)
delete mode 100644 he.c
tangke@tangke-laptop:~/Test/git-repo$ ls -al
total 20
drwxr-xr-x 3 tangke tangke 4096 2009-10-20 10:19 .
drwxr-xr-x 3 tangke tangke 4096 2009-10-20 10:12 ..
drwxr-xr-x 8 tangke tangke 4096 2009-10-20 10:21 .git
-rw-r--r-- 1 tangke tangke 35 2009-10-20 10:17 he.c
-rw-r--r-- 1 tangke tangke 0 2009-10-20 10:16 hel.c
-rw-r--r-- 1 tangke tangke 0 2009-10-20 10:19 hell.c
-rw-r--r-- 1 tangke tangke 13 2009-10-20 10:13 hello.c
tangke@tangke-laptop:~/Test/git-repo$ git rm hel.c
rm 'hel.c'
tangke@tangke-laptop:~/Test/git-repo$ ls
he.c hell.c hello.c
d.-f 强制删除某个文件或目录
4.git commit
5.git branch
a.-d,-D 删除某个分支
b.git branch upstream 建立一个名为upstream的分支
6.git checkout
7.git status
8.git log
9.git show
10.git diff
11.git rebase
11.git reset
项目跟踪工具的一个重要任务之一,就是使我们能够随时逆转(Undo)和恢复(Redo)某一阶段的工作。
git-reset 命令就是为这样的任务准备的。它将当前的工作分支的 头 定位到以前提交的任何版本中,它有三个重置的算法选项。
命令形式:
git-reset [--mixed | --soft | --hard] []
命令的选项:
--mixed
仅是重置索引的位置,而不改变你的工作树中的任何东西(即,文件中的所有变化都会被保留,也不标记他们为待提交状态),并且提示什么内容还没有被更新了。这个是默认的选项。
--soft
既 不触动索引的位置,也不改变工作树中的任何内容,我们只是要求这些内容成为一份好的内容(之后才成为真正的提交内容)。这个选项使你可以将已经提交的东西 重新逆转至“已更新但未提交(Updated but not Check in)”的状态。就像已经执行过 git-update-index 命令,但是还没有执行 git-commit 命令一样。
--hard
将工作树中的内容和头索引都切换至指定的版本位置中,也就是说自 之后的所有的跟踪内容和工作树中的内容都会全部丢失。因此,这个选项要慎用,除非你已经非常确定你的确不想再看到那些东西了
下面看一个例子:
tangke@tangke-laptop:~/Test/git-repo$ git status
# On branch upstream
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# modified: hell.c
#
tangke@tangke-laptop:~/Test/git-repo$ git commit -a -m "fixed"
[upstream caad228] fixed
1 files changed, 2 insertions(+), 0 deletions(-)
tangke@tangke-laptop:~/Test/git-repo$ git log | head -n 4
commit caad228ebaa38fc20480a11a18d597665e9413ee
Author: tangke
Date: Tue Oct 20 11:33:20 2009 +0800
//注意这里:
tangke@tangke-laptop:~/Test/git-repo$ git reset --soft HEAD^
tangke@tangke-laptop:~/Test/git-repo$ git log | head -n 4
commit 3f18109c69e4b75cea804cb069140dc41d93b4b7
Author: tangke
Date: Tue Oct 20 10:52:08 2009 +0800
X Y Z
--->(1) --->(2)
比如在执行(1)reset操作之后,HEAD就表示当前的Y,ORIG_HEAD表示X
在执行(2)reset操作之后,HEAD就表示Z,ORIG_HEAD表示Y
详细的版本类似于HEAD,ORIG_HEAD,HEAD~5等等看文章最后
12.git revert
13.git tag
该命令用来给git做标记
这里解释一下tag和branch之间的意思,我们一般在开发的过程中会碰到其中有一个版本需要发布,比如V1.0.1,那么我们就需要添加一个tag,使用
git tag -a V1.0.1
#而branch是在下面这种模式下面使用的:
#比如现在正在做某一个产品,然后另外一个公司过来可能要做同类型的产品,那么就可以在目前的基础上面作一个branch,
#比如git branch samsung
然后我们可以去.git/refs/tags/目录下面看到一个V1.0.1文件,cat V1.0.1
1d558316e20c8a346acd4c2ad69f2830e95f96b4
这个应该是一个唯一标记符,采用sha1加密算法,类似于commit 的那个号码
a.-a
添加一个没有任何标志的tag
$git tag -a V1.0.1 -m "fixed with tag named V1.0.1"
$git tag -l
V1.0.1
b.-s
默认是采用这种方式的,需要一个当前邮件的gpg-key-id,当然我们也可以使用其他的gpg-key-id,可以在.git/config文件中添加
[user]
signingkey =
c.-u key-id
直接输入git tag -u 就可以了
b.-l
列出目前所有的tag标记
$git tag -l
V1.0.2
V1.0.1
c.-d
删除一个tag
$git tag -d V1.0.1
$git tag -l
V1.0.2
e.--contains
查找包含某个commit的tag,我是这样理解的,查找某个commit被作为哪几个release发布了,因为一般tag 是被用来给产品正式发布使用的.
tangke@tangke-laptop:~/Test/git-repo$ git tag --contains 2ff656b5ee3188c79b665eb6a3d3910f2c90eba4
V1.0.2
V1.0.3
tangke@tangke-laptop:~/Test/git-repo$ git tag --contains 705cb9974b961931fe05a8d605315622808233fe
tangke@tangke-laptop:~/Test/git-repo$ git tag -a V1.0.4 -m "fixed with V1.0.4"
tangke@tangke-laptop:~/Test/git-repo$ git tag --contains 705cb9974b961931fe05a8d605315622808233fe
V1.0.4
14.git merge
15.git mv
15.git pull
16.git push
17.git fetch
18.git clone
19.git clean
20.git format-patch
21.git send-email
22.git
HEAD
HEAD^
HEAD~5
ORIG_HEAD
阅读(2103) | 评论(0) | 转发(0) |