Git Commit Basics
Understanding Git Commits in Version Control
Git commits are fundamental to version control, representing snapshots of your project at specific points in time. In software development workflow, commits track changes, enable collaboration, and provide a comprehensive history of code evolution.
Core Commit Concepts
Commits in Git serve multiple critical purposes:
- Record code changes
- Create trackable project versions
- Enable code rollback and history navigation
graph LR
A[Working Directory] --> B[Staging Area]
B --> C[Git Repository]
C --> D[Commit History]
Basic Commit Commands
Command |
Function |
Example |
git add |
Stage changes |
git add file.txt |
git commit |
Create snapshot |
git commit -m "Initial commit" |
git status |
Check repository status |
git status |
Practical Commit Example on Ubuntu 22.04
## Navigate to project directory
cd /home/developer/myproject
## Check current status
git status
## Stage specific file
git add README.md
## Commit with descriptive message
git commit -m "Add project README documentation"
## Verify commit
git log -n 1
Commit Identification
Each commit generates a unique SHA-1 hash, providing precise tracking of code modifications in git version control. This hash ensures data integrity and enables precise version management.