git commit
git commit
: Record changes to the repository.
The git commit
command is used in Git to save changes you've made to the repository. After you add changes to the staging area using git add
, you use git commit
to actually record those changes into the repository's history. When you make a commit, you're telling Git to take a snapshot of the staged changes at that point in time. This snapshot allows you to later return to this version, compare it with other versions, or share it with other developers.
Each commit contains the current contents of the staging area, the author and committer information, the commit date, and a commit message that you can use to describe the changes you've made. This allows you to track the history of your project, step by step.
Commits are the fundamental units of version history in Git. Each commit represents a specific point in the project's history, and the chain of commits represents the evolution of the project over time. By creating commits with meaningful messages, you can document what changes were made, when, and why, making it easier to understand the project's history and collaborate with others.
Examples
Commit staged changes with a given message:
git commit -m "Add login feature"
Commit staged changes with a message that you're going to compose in a default text editor:
git commit
Add all currently modified files and commit them:
git commit -a -m "Refactor codebase for better performance"
Amend the most recent commit (e.g., to fix a mistake in the commit message or changes):
git commit --amend -m "Corrected typo in previous commit"
If you must have a quotation mark as part of the message, you can place a backslash (\
) character before that quotation mark to escape it. In context of the command line and text strings overall, escaping usually means stripping something of special powers and treating it as plain text; here the special power is closing the string. Alternatively, you can wrap the commit message with single quotation marks. For example:
git commit -m "This is a \"message\""
OR
git commit -m 'This is a "message"'
Hi! I'm Alex, creator of GitByBit.
And this is Gitopedia—a reference that summarizes knowledge in my Git course.
Gitopedia is designed to be a personal knowledge base. When you progress through the main Git course in VS Code, you unlock all of these topics, one by one, bit by bit. This gives you time to digest the information and gradually build the mental model of Git. Here's an example of how it works:
Learning directly in VS Code lets you practice Git exactly as you would in real life, doing real jobs, writing real code. In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.
The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.