Make changes in Git

Jerry creates a copy of the repository on his machine and decides to perform basic operations. So he created the file string.c. After adding content, string.c will look like s

Jerry creates a copy of the repository on his machine and decides to perform basic operations. So he created the file string.c. After adding content, string.c will look like this:

 #include 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 = %dn" , s [ i ], my_strlen ( s [ i ])); return 0 ; } 

He compiles and checks his code and everything works normally. Now he can add these changes to the repository safely.

Git adds active files to the staging area.

 [jerry @ CentOS project] $ git status -s 
?? string
?? string.c

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

Git is pointing a bookmark question before naming the file. Obviously these files are not part of Git, and that's why Git doesn't know what to do with these files. That's why, Git is pointing a bookmark question before naming the file.

Jerry has added files to the staging area, the git status command will show the files in this area.

 [jerry @ CentOS project] $ git status -s 
A string.c
?? string

To commit the changes, he uses the git commit command followed by the -m option. If we forget the -m option. Git will open a text editor, where we can write multiple commit information.

 [jerry @ CentOS project] $ git commit -m 'Implemented my_strlen function' 

The above command will produce the result:

 [master cbe1249] Implemented my_strlen function 
1 files changed, 24 insertions (+), 0 deletions (-)
create mode 100644 string.c

After committing to view the log details, he ran the git log command. It will display the information of all commits with deposit IDs, depositors, commit dates and SHA-1 hash of deposit.

 [jerry @ CentOS project] $ git log 

The above command will produce the result:

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

Implemented my_strlen function


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

Initial commit

According to Tutorialspoint

Last lesson: Clone activity in Git

Next article: Review changes in Git

4.5 ★ | 2 Vote