git commit
A commit is a saved snapshot of your staged changes, along with a message describing what changed. Each commit has a unique ID (a hash) and forms part of the project's permanent history.
Commits should be small and focused, capturing one logical change at a time. This makes it much easier to review history, find bugs, or undo specific changes later.
git commit -m "message"Making a commit
After staging changes with git add, run `git commit -m "message"` to save a snapshot with a short description of the change.
Commit hashes
Every commit gets a unique SHA-1 hash, like a3f5c9e. You can use a shortened version of this hash to refer to a specific commit in other commands.
git add app.js
git commit -m "Add login validation"[main a3f5c9e] Add login validation
1 file changed, 10 insertions(+)Commits the staged change with a descriptive message and shows the new commit hash.
git commit -am "Fix typo in README"[main b7e21ff] Fix typo in README
1 file changed, 1 insertion(+), 1 deletion(-)The -a flag automatically stages tracked, modified files, combining add and commit in one step.
Key points
- git commit saves a snapshot of staged changes.
- Each commit needs a message describing the change.
- Every commit has a unique hash identifier.
- -am stages tracked changes and commits in a single command.
