What is Git Commit and How To Git Commit

What is Git Commit

Git commit is nothing but a snapchat of your git branch. Git commit will contain all your branch files like source code, directories…etc. generally we do git commit after made changes in our files or source code in the branch.

How To Git Commit

At any time, we can take a “snapshot” of all your project files in your project directory, and put it in your repository, this “snapshot” is called a commit object. Using git commit command we can take a snapshot of our branch files, but before that we have add files to git using git add command. git add command will add the files and file changes to git repository.

 

git repository example

Git Status Command

As shown in the above i have helloworld.java file in my repository, lets edit that file and save it. We can verify the modified files with git status command. Git status command will show the modified files in your git repository. In above image untracked files means, that file has not been added to git repository.

Git Add

Now add that file to git repository using git add command. After adding the files to git repository we can verify the our repository status with git status command. In above image you can see in green color new file, that means our file is added to git repository

Git Commit

git repository examples

as shown in the above command we can do git commit. Here -m represents the commit message. Commit messages can be very helpful, to yourself as well as to your team members. using commit message we can identify file changes that you have done in that particular commit.

The commit object contains

  1. a set of all our branch files,
  2. references to the “parents” of the commit object here (HEAD -> master)
  3. a unique “SHA1” name here(e3f6b0…………41389f)

How To list your Git Commits

using git log command we can list all our git commits in that particular branch. git log will command show you all the information about commits like who committed, when committed and commit message.

  • what is git commit
  • git commit examples
  • how to git commit

Leave a Reply

Your email address will not be published. Required fields are marked *