Git Commit Basics
Understanding Git Commits in Version Control
Git commits are fundamental snapshots in version control systems, representing specific points in a project's development history. Each commit captures the state of files at a particular moment, enabling precise tracking and management of code changes.
Core Commit Concepts
Commits in Git serve multiple critical functions:
- Create permanent code snapshots
- Track project evolution
- Enable collaborative repository management
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 log |
View commit history |
git log |
Practical Commit Example on Ubuntu 22.04
## Initialize a new Git repository
mkdir project_demo
cd project_demo
git init
## Create a sample file
echo "Hello, Git Commits!" > README.md
## Stage the file
git add README.md
## Create first commit
git commit -m "Add initial README file"
## View commit details
git log
Commit Identification
Each commit is uniquely identified by a 40-character SHA-1 hash, ensuring precise tracking of code snapshots and version control integrity.