Commit
A commit is the act of saving changes in a version control system (e.g., Git). Each commit captures the current state of the project’s files — code, documentation, configurations — and adds them to the change history.
Simply put, a commit is a snapshot of the project that allows you to roll back to a previous state or analyze who changed what and when.
What is a Commit
A commit is an action by which a developer saves changes to a local repository. Each commit is accompanied by a message (commit message) that briefly describes what was done — for example, added a new feature, fixed a bug, or updated documentation.
Example: “Added registration form” or “Fixed button display issue on mobile devices.”
What a Commit Looks Like in Git
Each commit has a unique identifier (SHA-1 hash), author, date, and message. Example console output:
text
commit 7a3b4c9d1ef2a4f6b0e4e93b9c8f3e0c56df7d9a
Author: Ivan Petrov <ivan.petrov@example.com>
Date: Mon Nov 4 10:25:18 2025 +0300
Added authorization module and updated login logic
This hash allows precise tracking of who, when, and what changes were made to the project.
How to Make a Commit
The Git commit process typically involves three steps:
- Stage files (add to the staging area):
git add .
Or selectively: git add src/login.js - Create a commit with a description of the changes:
git commit -m “Added login form validation” - (Optional) Push the commit to the remote repository:
git push origin main
Commit Structure
| Field | Description |
| Hash | Unique commit identifier |
| Author | Developer’s name and email |
| Date | Time of commit creation |
| Message | Brief description of changes |
| Changed Files | List of files affected by the commit |
Example of Multiple Commits
text
* 9a17b23 – Added ‘Buy’ button on product card
* 8b13e54 – Fixed cart display error
* 5c24d87 – Added Header component
* 1a91f12 – Project initialization
Each commit forms a chain that builds the project’s history. You can move between states and revert changes if necessary.
Types of Commits
| Type | Example Message | Purpose |
| feat | feat: added category filter | new feature |
| fix | fix: fixed authorization error | bug fix |
| refactor | refactor: optimized API code | code structure improvement |
| docs | docs: updated documentation | documentation changes |
| style | style: formatting fixes | formatting, no logic changes |
| test | test: added unit tests | adding or updating tests |
| chore | chore: updated dependencies | maintenance changes (configs, build) |
Such conventions are described in the Conventional Commits standard — they help automate releases and changelog generation.
Commit Best Practices
- Write short and clear messages. A good message is under 50 characters, in the imperative mood:
“Add form validation”, “Fix filter error”. - Make commits logically cohesive. Each commit should solve one task — easier to review and revert.
- Do not commit temporary or unnecessary files. Add them to .gitignore.
- Check code before committing. Use git diff or git status to ensure all necessary changes are included.
- Add a description in the commit body if there are many changes:
git commit -m “Added Google OAuth” -m “Added OAuth2, updated routing, fixed tests”
Undoing and Amending Commits
| Command | Action |
| git commit –amend | amend the last commit (message or files) |
| git reset HEAD~1 | undo the last commit, keeping changes in the code |
| git revert <hash> | create a new commit that undoes changes from a previous one |
| git log | view commit history |
Important: Be careful when amending commits already pushed to the server — it can cause conflicts for other developers.
Commits and Pull Requests
Commits are the foundation of a Pull Request (PR). When a developer creates a PR, they are essentially proposing to merge their commits into the main branch. High-quality, atomic commits with clear messages help reviewers quickly understand the changes and simplify the review process.
Example Workflow
bash
git checkout -b feature/add-search
# … work on code …
git add .
git commit -m “feat: added site search”
git push origin feature/add-search
# Create a Pull Request on GitHub
After the PR is approved, the commit becomes part of the main branch (main).
Conclusion
A commit is a fundamental element of a project’s history that records changes and allows you to manage code evolution. Well-formatted commits make a project transparent, enable quick bug detection, and help track the evolution of functionality.
Free in the Telegram bot 