Git – 查看更改

Git – 查看更改


查看提交细节后,Jerry 意识到字符串长度不能为负数,这就是他决定更改 my_strlen 函数的返回类型的原因。

Jerry 使用git log命令查看日志详细信息。

[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

Jerry 使用git show命令查看提交详细信息。git show 命令将SHA-1提交 ID 作为参数。

[jerry@CentOS project]$ git show cbe1249b140dad24b2c35b15cc7e26a6f02d2277

上述命令将产生以下结果 –

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

Implemented my_strlen function


diff --git a/string.c b/string.c
new file mode 100644
index 0000000..187afb9
--- /dev/null
+++ b/string.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+int my_strlen(char *s)
+{
   +
   char *p = s;
   +
   +
   while (*p)
   + ++p;
   + return (p -s );
   +
}
+

他将函数的返回类型从 int 更改为 size_t。测试代码后,他通过运行git diff命令来检查他的更改

[jerry@CentOS project]$ git diff

上述命令将产生以下结果 –

diff --git a/string.c b/string.c
index 187afb9..7da2992 100644
--- a/string.c
+++ b/string.c
@@ -1,6 +1,6 @@
#include <stdio.h>

-int my_strlen(char *s)
+size_t my_strlen(char *s)
{
   char *p = s;
   @@ -18,7 +18,7 @@ int main(void)
};
for (i = 0; i < 2; ++i)
{
   - printf("string lenght of %s = %d\n", s[i], my_strlen(s[i]));
   + printf("string lenght of %s = %lu\n", s[i], my_strlen(s[i]));
   return 0;
}

Git diff在新添加的行前显示‘+’,删除的行显示‘-‘ 号

觉得文章有用?

点个广告表达一下你的爱意吧 !😁