A commit is a saved snapshot of your project at a specific point in time โ like a save point in a video game!
What Is a Commit
In Simple Terms
Imagine you’re writing a book:
- Without Git: You write all day, your computer crashes, and all the text is lost ๐ฑ
- With Git commits: Every 30 minutes you make a “save” โ you can roll back to any point โ
Commit = checkpoint in your code!
What’s Stored in a Commit?
Every commit contains:
- Snapshot of files โ a full snapshot of the project
- Author โ who made the changes
- Date and time โ when it was done
- Message โ what changed (commit message)
- Unique ID โ hash (e.g.:
a1b2c3d...) - Reference to parent โ the previous commit
It’s like a photograph:
- A snapshot of the moment โ
- With date and signature โ
- Can be viewed later โ
Why Do You Need Commits?
1. Change History ๐
# You can see EVERYTHING that happened:
commit a1b2c3d
Author: Ivan
Date: April 10, 4:30 PM
fix: fix auth bug
commit x7y8z9w
Author: Maria
Date: April 10, 2:15 PM
feat: add registration form
You can answer questions like:
- Who wrote this code?
- When was this feature added?
- Why was this file changed?
2. Reverting Changes โฎ๏ธ
Imagine:
- Added a new feature โ everything broke
- With commits: roll back 1 hour โ everything works!
# One command โ and you're back in time
git checkout previous-commit
Without commits: Ctrl+Z won’t help once you’ve closed the editor!
3. Team Collaboration ๐ฅ
The problem:
- You’re working on app.py
- A colleague is also changing app.py
- How do you combine?
The solution โ commits!
- Each person makes their own commits
- Git knows how to merge
- Conflicts are resolved transparently
4. Code Backup ๐พ
Commits on GitHub = cloud backup:
- Your computer burns down โ code is safe โ
- Accidentally deleted a file โ restored โ
- Virus encrypted the drive โ clone from GitHub โ
Commit in Detail
Commit vs Saving a File
| Action | Save File (Ctrl+S) | Git Commit |
|---|---|---|
| What | Writes file to disk | Saves a project snapshot |
| History | No history | Full history |
| Rollback | Can’t go back | Can roll back to any point |
| Team | Who, what, when โ unknown | Author, date, message visible |
| Backup | Only on your PC | Syncs with GitHub |
Takeaway: Ctrl+S saves the file, Git commit saves a MOMENT in the project’s history!
Example Commit
# 1. Changed the file
echo "print('Hello')" > app.py
# 2. Added to staging
git add app.py
# 3. Made a commit
git commit -m "feat: add greeting function"
# Result:
[main a1b2c3d] feat: add greeting function
1 file changed, 1 insertion(+)
What happened:
1. Git took a snapshot of the current state
2. Recorded it in history with your message
3. Assigned unique ID a1b2c3d
Anatomy of a Commit
git log
Shows:
commit a1b2c3d4e5f6g7h8i9j0 โ Unique hash
Author: Ivan Ivanov <ivan@example.com> โ Who
Date: Thu Apr 10 16:30:00 2026 +0300 โ When
feat: add registration form โ What (commit message)
- Created /register page
- Email and password validation
- Database integration
How to Commit Correctly
How Often to Commit?
โ Good practice:
1 commit = 1 logical change
Examples:
- Fixed a bug โ commit
- Added a feature โ commit
- Updated README โ commit
- Refactored a function โ commit
Rule of thumb: every 30-60 minutes of work or after completing a task
โ Bad practice:
Too rarely:
# Worked for a week โ 1 giant commit
git commit -m "done" # 150 files changed!
Problems:
- Impossible to understand what changed
- Can’t partially revert
- Code review is a nightmare
Too often:
git commit -m "added 1 line" # ร 50 times per hour
Problems:
- History is polluted
- Hard to find the change you need
The sweet spot:
# Monday
git commit -m "feat: add user model"
git commit -m "feat: create login form"
git commit -m "fix: fix email validation"
# = 3 clear commits for the day
What NOT to Commit?
โ Never:
- Passwords, API keys, tokens
- .env file with secrets
- node_modules/, __pycache__/
- Large binary files (videos, archives)
- Temp files, logs
Use .gitignore!
Commits and GitHub
Local commits:
- Made on your computer
- Nobody sees them yet
- Can be changed/deleted
After push:
- Commits are on GitHub
- Visible to the entire team
- Harder to change (requires force push)
Visualization and Tools
Visual Representation
Time โ
[Commit 1] [Commit 2] [Commit 3] [Commit 4]
Init Add login Fix bug Add docs
โ โ โ โ
mainโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Each โ = a commit = a point in the project’s history!
You can jump to any of them:
git checkout Commit-2 # returned to the "Add login" moment
Commits in GitHub Desktop
Visual process:
- Changes โ see modified files
- Diff โ see what exactly changed (green/red)
- Summary โ write commit message
- Commit to main โ snapshot the moment!
- Push โ send to GitHub
Clear and visual! ๐จ
Best Practices and Career
Best Practices
โ
DO:
- Commit frequently (every 30-60 minutes)
- Write clear messages
- One commit = one task
- Review diff before committing
- Commit working code
โ DON’T:
- Giant commits (100+ files)
- Commit broken code
- Meaningless messages (“update”, “fix”)
- Commit secrets and passwords
- Commit temp files
Why This Matters for Your Career
Employers look at:
- GitHub profile โ how many commits, how often
- Commit quality โ clear messages
- Project history โ code evolution
- Contributions โ contributions to open source
Good commits = a mark of a professional! ๐ผ
Conclusion
Commit = save point in a game:
- Checkpoint in code โ
- Can roll back โ
- Full history of all changes โ
- Backup on the server (GitHub) โ
Start small:
1. Worked 30-60 minutes โ commit
2. Fixed a bug โ commit
3. Added a feature โ commit
4. Updated documentation โ commit
Remember: Git commits are a time machine for your code! โฐ
Next step: learn how to write proper commit messages! โ๏ธ
๐ฌ Comments (0)
No comments yet
Be the first to share your opinion about this article!