Basics

Git Commit

Committing Changes

Git commit saves staged changes with a message using -m.

Introduction to Git Commit

The git commit command is an essential part of the Git version control system, allowing developers to save changes to the local repository. Each commit is a snapshot of your project at a specific point in time. This command is used after changes have been staged and is accompanied by a message that describes the changes.

Basic Syntax of Git Commit

The simplest way to create a commit is to use the -m flag, which allows you to add a commit message directly from the command line. Here is the basic syntax:

Importance of Commit Messages

Commit messages are crucial as they provide context and understanding of the changes made. A well-written commit message helps other developers (and your future self) to understand what you were trying to accomplish with the changes. It's a best practice to keep commit messages clear and concise.

Committing Staged Changes

Before committing, ensure that your changes are staged. You can stage changes using the git add command. Once staged, you can commit these changes:

Viewing Commit History

After committing changes, you can view the commit history using:

This command displays the list of commits in your repository, providing details such as commit ID, author, date, and message.

Amending the Last Commit

If you need to modify the last commit, you can use the --amend option. This is useful for updating the commit message or adding forgotten changes:

Be cautious when amending commits that have already been pushed to a shared repository, as this can lead to complications for other collaborators.

Previous
Add
Next
Log