分类: BSD
2010-06-10 11:00:36
helight@helight:~/mywork/zhwen.org$ ssh-keygen生成密钥,用户通信加解密。如果接受默认设置,那么生成2048bits RAS的密钥,私钥和公钥文件分别位于:~/.ssh/id_rsa和~/.ssh/id_rsa.pub。用户需要向服务器管理员提供公钥 (id_rsa.pub),在用户同步版本库时对用户进行身份认证。用户必须妥善保管私钥。
Generating public/private rsa key pair.
Enter file in which to save the key (/home/helight/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/helight/.ssh/id_rsa.
Your public key has been saved in /home/helight/.ssh/id_rsa.pub.
The key fingerprint is:
e0:4a:ba:d9:ba:b9:7a:0a:e4:aa:86:6c:a7:d8:85:c0 helight@helight
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| . |
|. . . |
|.E . . S |
|o. + . |
|+.o o |
|==.B |
|X=@+. |
+-----------------+
helight@helight:~/mywork/zhwen.org$ vim /home/helight/.ssh/
id_rsa id_rsa.pub known_hosts
helight@helight:~/kernel-mod/hello$ git-config user.name Zhwen Xu配置用户名,在生成补丁、日志时使用。git-config命令带--global选项是对所有用户信息进行配置,默认只针对对当前用户。 git-config中写入配置信息。 如果git-config加了--global选项,配置信息就会写入到~/.gitconfig文件中。 因为你可能用不同的身份参与不同的项目,而多个项目都用git管理,所以建议不用global配置。
helight@helight:~/kernel-mod/hello$ git-config user.email Helight.Xu@gmail.com
helight@helight:~/kernel-mod/hello$ git-config --list
user.name=Zhwen Xu
user.email=Helight.Xu@gmail.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
helight@helight:~/kernel-mod/hello$
helight@helight:~/kernel-mod/hello$ ls -a接着执行上面所说的命令:
. .. hello.c Makefile
helight@helight:~/kernel-mod/hello$
helight@helight:~/kernel-mod/hello$ git-init-db执行完上面的命令之后用“ls -a”来看,就会发现多了一个“.git”的文件,这个文件就是hello个小项目的git仓库。关于这个仓库有兴趣的读者可以进入该文件夹继续分析。 接下来介绍如何将项目中的文件添加到仓库中,让git来作版本管理。将文件添加到git仓库中的命令是git-add,当然这并不是真的将文件copy到git的仓库文件夹中。只是在仓库中标识它,以示要用它git来管理它了。具体操作如下:
Initialized empty Git repository in /home/helight/kernel-mod/hello/.git/
helight@helight:~/kernel-mod/hello$ ls -a
. .. .git hello.c Makefile
helight@helight:~/kernel-mod/hello$
helight@helight:~/kernel-mod/hello$ git-add hello.c可以看到添加可以是单个文件添加,也可以是多个文件一起添加。接下来是提交和项目状态的查看。相信有了前面的一点说明大家对git的管理也多少有点感觉了吧!
helight@helight:~/kernel-mod/hello$ git-add *
helight@helight:~/kernel-mod/hello$
helight@helight:~/kernel-mod/hello$ git-status第一个“git-status”的提示信息告诉我们版本库中加入了两个新的文件(这是和上一个版本的变化),并且 git 提示我们提交这些文件,我们可以通过 git-commit 命令来提交。提交后再次使用就会提示没有变化需要提交了。
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached..." to unstage)
#
# new file: Makefile
# new file: hello.c
#
helight@helight:~/kernel-mod/hello$ git-commit -m "init the project" ./*
Created initial commit f4808f0: init the project
2 files changed, 27 insertions(+), 0 deletions(-)
create mode 100644 Makefile
create mode 100644 hello.c
helight@helight:~/kernel-mod/hello$ git-status
# On branch master
nothing to commit (working directory clean)
helight@helight:~/kernel-mod/hello$
helight@helight:~/kernel-mod/hello$ git-branch可以看出“git-branch”是查看分支情况和创建分支,”git-checkout”个用来切换分支。其中“*”表示当前工作的分支。
* master
helight@helight:~/kernel-mod/hello$ git-branch helight
helight@helight:~/kernel-mod/hello$ git-branch
helight
* master
helight@helight:~/kernel-mod/hello$ git-checkout helight
Switched to branch "helight"
helight@helight:~/kernel-mod/hello$ git-branch
* helight
master
helight@helight:~/kernel-mod/hello$
helight@helight:~/kernel-mod/hello$ git-branch xux
helight@helight:~/kernel-mod/hello$ git-branch
* helight
master
xux
helight@helight:~/kernel-mod/hello$ git-branch -D xux
Deleted branch xux.
helight@helight:~/kernel-mod/hello$ git-branch
* helight
master
helight@helight:~/kernel-mod/hello$
helight@helight:~/kernel-mod/hello$ git-show-branch
* [helight] init the project
! [master] init the project
--
*+ [helight] init the project
helight@helight:~/kernel-mod/hello$ git-diff
diff --git a/hello.c b/hello.c
index 843a6b8..c762de7 100644
--- a/hello.c
+++ b/hello.c
@@ -14,6 +14,7 @@ static int __init hello_init(void)
static void __exit hello_exit(void)
{
printk("kernel: %s\n","Bey world!");
+ printk("kernel: %s\n","Bey world!");
}
module_init(hello_init);
helight@helight:~/kernel-mod/hello$ git-commit -m "some change" ./*
Created commit 2d900d9: some change
1 files changed, 1 insertions(+), 0 deletions(-)
helight@helight:~/kernel-mod/hello$ git-whatchanged譬如我们要查看标号为 master和helight的版本的差异情况, 我们可以使用这样的命令:
commit 2d900d918d24943b32f3d41b1974e0375be02c9e
Author: Zhenwen Xu
Date: Wed Nov 12 22:09:45 2008 +0800
some change
:100644 100644 843a6b8... c762de7... M hello.c
commit f4808f013f44e815831a3830a19925472be83424
Author: Zhenwen Xu
Date: Wed Nov 12 21:53:52 2008 +0800
init the project
:000000 100644 0000000... c151955... A Makefile
:000000 100644 0000000... 843a6b8... A hello.c
helight@helight:~/kernel-mod/hello$
helight@helight:~/kernel-mod/hello$ git-diff helight master
diff --git a/hello.c b/hello.c
index c762de7..843a6b8 100644
--- a/hello.c
+++ b/hello.c
@@ -14,7 +14,6 @@ static int __init hello_init(void)
static void __exit hello_exit(void)
{
printk("kernel: %s\n","Bey world!");
- printk("kernel: %s\n","Bey world!");
}
module_init(hello_init);
helight@helight:~/kernel-mod/hello$
补丁制作: git-format-patch
helight@helight:~/kernel-mod/hello$ vim hello.c
helight@helight:~/kernel-mod/hello$ git-commit -m "change by helight" hello.c
Created commit 4772773: change by helight
1 files changed, 1 insertions(+), 0 deletions(-)
helight@helight:~/kernel-mod/hello$ git-format-patch -s master
0001-change-by-helight.patch
helight@helight:~/kernel-mod/hello$ cat 0001-change-by-helight.patch
From 4772773ecbbde66b8febc1d8aed0da67d480f1e4 Mon Sep 17 00:00:00 2001
From: Zhenwen Xu
Date: Thu, 13 Nov 2008 10:30:10 +0800
Subject: [PATCH] change by helight
Signed-off-by: Zhenwen Xu
---
hello.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/hello.c b/hello.c
index 89795d2..2cbf9ee 100644
--- a/hello.c
+++ b/hello.c
@@ -6,6 +6,7 @@ MODULE_LICENSE("GPL");
static int __init hello_init(void)
{
printk("kernel: %s\n","Hello world!");
+ printk("kernel: %s\n","This is Helight.Xu!");
return 0;
}
--
1.5.6.5
helight@helight:~/kernel-mod/hello$
helight@helight:~/kernel-mod/hello$ git-checkout master但是更多的是将现在的工作pull到主分支上去,如下命令:
Switched to branch "master"
helight@helight:~/kernel-mod/hello$ git-merge "merge helight" HEAD helight
Updating f4808f0..2d900d9
Fast forward
hello.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
helight@helight:~/kernel-mod/hello$
helight@helight:~/kernel-mod/hello$ vim hello.cgit-pull:将工作更新到分支上
helight@helight:~/kernel-mod/hello$ git-commit -m "another change" ./*
Created commit 1d6b878: another change
1 files changed, 0 insertions(+), 3 deletions(-)
helight@helight:~/kernel-mod/hello$ git-checkout master现在来看看如何退回到上一个版本:git-reset
Switched to branch "master"
helight@helight:~/kernel-mod/hello$ git-pull . helight
From .
* branch helight -> FETCH_HEAD
Updating 2d900d9..1d6b878
Fast forward
hello.c | 3 ---
1 files changed, 0 insertions(+), 3 deletions(-)