但查看提交詳細資料后,Byron 實現字符串的長度不能為負數,所以他決定改變my_strlen函數的返回類型。
Byron 使用git日志命令來查看日志信息。
[byron@CentOS project]$ git log
上面的命令會產生以下結果。
commit cbe1249b140dad24b2c35b15cc7e26a6f02d2277
Author: Byron <xiaobosun@gridinfo.com.cn>
Date: Wed Sep 11 08:05:26 2015 +0530
Implemented my_strlen function
Byron 使用git show命令查看提交的細節。 Git的show命令的SHA-1提交ID作為參數。
[byron@CentOS project]$ git show cbe1249b140dad24b2c35b15cc7e26a6f02d2277
上面的命令會產生以下結果。
commit cbe1249b140dad24b2c35b15cc7e26a6f02d2277
Author: Byron <xiaobosun@gridinfo.com.cn>
Date: Wed Sep 11 08:05:26 2015 +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命令。
[byron@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
", s[i], my_strlen(s[i]));
+ printf("string lenght of %s = %lu
", s[i], my_strlen(s[i]));
return 0;
}
Git 的差異顯示+號前行,這是新增加的,并顯示符號被刪除。