发布于 2015-06-21 11:47:42 | 303 次阅读 | 评论: 0 | 来源: 网络整理

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 = %dn", s[i], my_strlen(s[i]));

   return 0;
}

他编译和测试代码,一切工作正常。现在,他可以放心地添加这些修改到版本库。

Git 添加操作添加文件到暂存区。


[jerry@CentOS project]$ git status -s
?? string
?? string.c

[jerry@CentOS project]$ git add string.c

Git是显示文件名前的问号。显然,这些文件不属于Git,Git 不知道该怎么用这些文件。这就是为什么Git是文件名前显示问号。

Jerry 添加文件到存储区域,git的状态命令将显示文件暂存区域。


[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 日志命令。它会显示提交ID所有提交的信息,提交作者,提交日期和提交的 SHA-1散列。


[jerry@CentOS project]$ git log

上面的命令会产生以下结果。


commit cbe1249b140dad24b2c35b15cc7e26a6f02d2277
Author: Jerry Mouse <jerry@phperz.com>
Date: Wed Sep 11 08:05:26 2013 +0530

Implemented my_strlen function


commit 19ae20683fc460db7d127cf201a1429523b0e319
Author: Tom Cat <tom@phperz.com>
Date: Wed Sep 11 07:32:56 2013 +0530

Initial commit
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务