Git 执行变更
Git 执行变更
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、作者、日期和哈希值。
[jerry@CentOS project]$ git log
上述操作将产生如下输出:
commit cbe1249b140dad24b2c35b15cc7e26a6f02d2277 Author: Jerry Mouse <jerry@tutorialspoint.com> Date: Wed Sep 11 08:05:26 2013 +0530 Implemented my_strlen function commit 19ae20683fc460db7d127cf201a1429523b0e319 Author: Tom Cat <tom@tutorialspoint.com> Date: Wed Sep 11 07:32:56 2013 +0530 Initial commit