Skip to main content

Commit

Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/commit

In short

A commit is a saved snapshot of a project's files in Git, recorded with a unique ID, an author, a timestamp, and a message describing what changed.

What is a commit in Git?

A commit records the state of your project at a specific moment. Each commit stores a snapshot of the tracked files, who made it, when it was made, a message explaining the change, and a link to the commit or commits that came before it. Chained together through those links, commits form the project's history.

Before committing, you choose which changes to include by adding them to the staging area with git add. Running git commit then saves exactly those staged changes. Every commit gets a unique identifier called a hash, a long string of letters and digits, which you can use to view, compare, or revert that exact version.

Commits work like save points in a document's history, each with a short note explaining what was done. Good commits are small and focused on one logical change, with a clear message like 'Fix login redirect loop' rather than 'updates'. This makes the history easy to read, review, and undo.

Committing is not the same as sharing. A commit exists only in your local repository until you run git push to send it to a remote repository. The word commit is also used in databases, where it means making a transaction's changes permanent.

At a glance

Three commits in a row. Each one is a snapshot of the project with a unique hash, an author, a time and a message, and each points back to the commit before it, its parent; the main branch points at the newest.parentparenta1f3c9eAdd login pageAda · Mon 10:027b2d4e1Fix header typoLinus · Mon 11:40e9c05b8Hash passwordsAda · Tue 09:15snapshot of every filemain
Following the parents from the newest commit back gives the whole history. Commits stay on your machine until you push them.

Key takeaways

  • A commit is a snapshot of staged changes plus metadata: author, date, message, and parent.
  • Each commit has a unique hash that identifies it.
  • Commits stay local until you push them to a remote repository.
  • Small, focused commits with clear messages make history easy to understand.

Example

Creating and inspecting commitsbash
# See what has changed
git status

# Stage a specific file for the next commit
git add src/login.ts

# Save the staged changes with a descriptive message
git commit -m "Fix login redirect loop"

# View the three most recent commits (short hash and message)
git log --oneline -3

# Reword the last commit's message (only before pushing)
git commit --amend -m "Fix redirect loop after login"

Readers ask

How do I undo a commit in Git?

To undo a commit that has already been shared, use git revert <hash>, which creates a new commit that reverses it. To undo your most recent local commit while keeping its changes in your files, use git reset --soft HEAD~1.

What makes a good commit message?

A good commit message starts with a short summary line, around 50 characters, written as a command, such as 'Add password reset email'. If more context is needed, add a blank line followed by a longer explanation of why the change was made.

What is the difference between git commit and git push?

git commit saves a snapshot in your local repository. git push uploads your local commits to a remote repository so others can see them.

See also

Sources

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings