Git-perform-changes
提供:Dev Guides
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の追加操作により、ファイルがステージング領域に追加されます。
[jerry@CentOS project]$ git status -s
?? string
?? string.c
[jerry@CentOS project]$ git add string.c
Gitはファイル名の前に疑問符を表示しています。 明らかに、これらのファイルはGitの一部ではないため、Gitはこれらのファイルをどう処理するのか分からないのです。 そのため、Gitはファイル名の前に疑問符を表示しています。
Jerryはファイルをスタッシュ領域に追加しました。gitstatusコマンドはステージング領域に存在するファイルを表示します。
[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 project]$ git log
上記のコマンドは、次の結果を生成します-
commit cbe1249b140dad24b2c35b15cc7e26a6f02d2277
Author: Jerry Mouse <[email protected]>
Date: Wed Sep 11 08:05:26 2013 +0530
Implemented my_strlen function
commit 19ae20683fc460db7d127cf201a1429523b0e319
Author: Tom Cat <[email protected]>
Date: Wed Sep 11 07:32:56 2013 +0530
Initial commit