Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

Commit in Git: Explained

Understand Commit in Git with clear explanations, practical examples, and useful tips. This updated guide covers the essential concepts and common mistakes.

Table of Contents

Commit in Git is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.

Jerry commits (deposits) the changes and he wants to correct them for his recent commits. In this case, the function git commit -a will help do this. This function changes the last commit including your commit message; It creates a new commit ID.

Before custom operation, he checks the commit log.

 [jerry @ CentOS project] $ git log 

The above command will produce the following 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 

Jerry commits new changes to the --a function, and observes the commit log.

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

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

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

 [jerry @ CentOS project] $ git commit --a -m 'Changed return type of my_strlen to size_t' 
 [master d1e19d3] Changed return type of my_strlen to size_t 
 1 files changed, 24 insertions (+), 0 deletions (-) 
 create mode 100644 string.c 

Now git log will show a new commit message with the new commit ID:

 [jerry @ CentOS project] $ git log 

The above command will produce the following result:

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

 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 

Next lesson: Push operation in HTML

FAQ

What is Commit in Git?

Jerry commits (deposits) the changes and he wants to correct them for his recent commits.

Why is Commit in Git important?

A clear understanding of Commit in Git helps you make informed decisions, avoid common mistakes, and use the relevant tools or techniques more effectively.

How should beginners approach Commit in Git?

Start with the fundamental concepts, follow the examples step by step, and test each change in a safe environment before applying it to important systems or data.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.