Updating Changes


Modify Existing Function

Tom runs the clone command and creates a new file called string.c. He uses the git log command to find out who contributed this file to the repository and why.
[tom@CentOS ~]$ git clone gituser@git.server.com:project.git

The output of the command above is as follows:
Remote: /home/tom/project/.git/ remote: Initialized empty Git repository in /home/tom/project/.git/ Counting objects: six completed.
remote: Object compression: 100% (4/4), completed.
Objects received: 100% (6/6), 726 bytes, completed.
total 6 (delta 0), reused 0 (delta 0),

The Clone command creates a new directory within the current working directory. He executes the git log command after changing the directory to the newly formed directory.

[tom@CentOS ~]$ cd project/

[tom@CentOS project]$ git log

The output of the command above is as follows:
commit d1e19d316224cddc437e3ed34ec3c931ad803958
Author: Jerry Mouse
Date: Wed Sep 11 08:05:26 2013 +0530

my strlen's return type has been changed to size t.

commit 19ae20683fc460db7d127cf201a1429523b0e319
Tom Cat (tom@tutorialspoint.com) is the author.
Wed Sep 11 07:32:56 2013 +0530 Date: Wed Sep 11 07:32:56 2013 +0530

The initial commitment

After looking at the log, he discovers that Jerry added the string.c file to support fundamental string operations. Jerry's coding has piqued his interest. So he opens string.c in a text editor and detects a flaw right away. Jerry does not use a constant pointer in his strlen method. As a result, he chooses to change Jerry's code. The code looks like this once it's been modified:

[tom@CentOS project]$ git diff

The output of the command above is as follows:

diff --git a/string.c b/string.c index 7da2992..32489eb 100644 --- a/string.c +++ b/string.c @@ -1,8 +1,8 @@ #include <stdio.h> -size_t my_strlen(char *s) +size_t my_strlen(const char *s) { - char *p = s; + const char *p = s; while (*p) ++p; }

He commits his change after testing it.
[tom@CentOS project]$ git status -s
M string.c
?? string

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

[tom@CentOS project]$ git commit -m 'Changed char pointer to const char pointer.'
[master cea2c00] Changed char pointer to const char pointer
1 files changed, 2 insertions(+), 2 deletions(-)

[tom@CentOS project]$ git log

The output of the command above is as follows:

commit cea2c000f53ba99508c5959e3e12fff493b
Author: Tom Cat
Date: Wed Sep 11 08:32:07 2013 +0530

Changed char pointer to const char pointer

commit d1e19d316224cddc437e3ed34ec3c931ad803958
Author: Jerry Mouse
Date: Wed Sep 11 08:05:26 2013 +0530

The changed return type of my_strlen to size_t

commit 19ae20683fc460db7d127cf201a1429523b0e319
Author: Tom Cat
Date: Wed Sep 11 07:32:56 2013 +0530
Initial commit

Fetch Latest Changes
Jerry uses the git pull command to synchronize his local and remote repositories.
[jerry@project CentOS]
git pull $

The output of the command above is as follows:

remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From git.server.com:project
d1e19d3..cea2c00 master −> origin/master
First, rewinding head to replay your work on top of it...
Applying: Added my_strcpy function

Jerry views the log messages after the pull operation and discovers the specifics of Tom's commit with commit ID. cea2c000f53ba99508c5959e3e12fff493ba6f69
[jerry@CentOS project]$ git log

The above command will produce the following result −
commit e86f0621c2a3f68190bba633a9fe6c57c94f8e4f
Author: Jerry Mouse
Date: Wed Sep 11 08:41:42 2013 +0530

Added my_strcpy function

commit cea2c000f53ba99508c5959e3e12fff493ba6f69
Author: Tom Cat
Date: Wed Sep 11 08:32:07 2013 +0530

Changed char pointer to const char pointer

commit d1e19d316224cddc437e3ed34ec3c931ad803958
Author: Jerry Mouse
Date: Wed Sep 11 08:05:26 2013 +0530

The changed return type of my_strlen to size_t

commit 19ae20683fc460db7d127cf201a1429523b0e319
Author: Tom Cat
Date: Wed Sep 11 07:32:56 2013 +0530
Initial commit

Now, Jerry's local repository is fully integrated with the remote storage. So he can safely push his changes.
[jerry@CentOS project]$ git push origin master

The above command will produce the following result −
Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 455 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To gituser@git.server.com:project.git
cea2c00..e86f062 master −> master