Git Commit

git commit saves your staged changes to the local repository as a permanent snapshot. It creates a new commit object with a unique identifier based on the changes made, along with a message that describes them. This is the fifth post in this site’s Git command guide, following Git Add . (All).

Basic Usage

Here’s how to use git commit in the typical workflow:

  1. After making changes to your files, add them to the staging area with git add.
  2. Once you’ve added all the changes you want to commit, run the git commit command followed by a -m flag and a message inside quotes describing the changes made. For example:
git commit -m "Added new feature to login page"
  1. The commit is now saved to your local repository with a unique identifier, allowing you to easily track and revert to previous versions of your code.

It’s important to note that committing changes locally only saves them to your local Git repository. To share the changes with others or push them to a remote repository, you’ll need to run git push after committing.

How git commit Works

  • Every commit records a snapshot of the staging area at that moment, not a diff. Git stores it as a tree of objects pointing at blobs (file contents), a parent commit hash, and the metadata you supply (author, timestamp, message).
  • The -m flag lets you write the commit message inline. Without it, Git opens your configured editor so you can write a multi-line message.
  • Committing does not affect remote repositories — that requires git push, covered later in the series.

Useful Resources

See Also: This Site’s Git Command Guide

This post is part of a 13-part Git command guide on this site:

Conclusion

git commit is the moment your staged changes become part of the permanent project history. With your work committed locally, the next thing to check is the overall state of your repository — covered in Git Status.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.