Jerry克隆存储库并决定实现基本的字符串操作.所以他创建了string.c文件.添加内容后,string.c将如下所示 :
#include <stdio.h> int my_strlen(char *s) { char *p = s; while (*p) ++p; return (p - s); } int main(void) { int i; char *s[] = { "Git tutorials", "Tutorials Point" }; for (i = 0; i < 2; ++i) printf("string lenght of %s = %d\n", s[i], my_strlen(s[i])); return 0; }
他编译并测试了他的代码,一切正常.现在,他可以安全地将这些更改添加到存储库.
Git add操作将文件添加到临时区域.
[jerry@CentOS project]$ git status -s ?? string ?? string.c [jerry@CentOS project]$ git add string.c
Git在文件名前显示问号.显然,这些文件不是Git的一部分,这就是为什么Git不知道如何处理这些文件.这就是为什么,Git在文件名之前显示一个问号.
Jerry已将文件添加到存储区域,git status命令将显示存档区域中存在的文件.
[jerry@CentOS project]$ git status -s A string.c ?? string
要提交更改,他使用git commit命令后跟-m选项.如果我们省略-m选项. Git将打开一个文本编辑器,我们可以编写多行提交消息.
[jerry@CentOS project]$ git commit -m 'Implemented my_strlen function'
上述命令将产生以下结果 :
[master cbe1249] Implemented my_strlen function 1 files changed, 24 insertions(+), 0 deletions(-) create mode 100644 string.c
在提交查看日志详细信息后,他运行git log命令.它将显示所有提交的信息及其提交ID,提交作者,提交日期和提交的 SHA-1 哈希.
[jerry @ CentOS项目] $ git log
上述命令将产生以下结果 :
commit cbe1249b140dad24b2c35b15cc7e26a6f02d2277 Author: Jerry Mouse <jerry@IT屋.com> Date: Wed Sep 11 08:05:26 2013 +0530 Implemented my_strlen function commit 19ae20683fc460db7d127cf201a1429523b0e319 Author: Tom Cat <tom@IT屋.com> Date: Wed Sep 11 07:32:56 2013 +0530 Initial commit