Git Commit Basics
Understanding Git Commits in Version Control
Git commits are fundamental to version control, serving as snapshots of your project's changes. In software development workflow, commits represent specific points in your project's history, capturing code modifications, additions, and deletions.
Key Commit Characteristics
Characteristic |
Description |
Unique Identifier |
Each commit has a unique SHA-1 hash |
Metadata |
Contains author, timestamp, and commit message |
Immutable |
Commits are permanent and cannot be altered |
Basic Commit Operations
## Initialize a Git repository
git init
## Stage files for commit
git add file.txt
git add . ## Stage all changes
## Create a commit
git commit -m "Initial project setup"
## View commit history
git log
Commit Workflow Visualization
gitGraph
commit id: "Initial Commit"
commit id: "Add Feature A"
branch develop
commit id: "Implement Feature B"
checkout main
commit id: "Bug Fix"
Understanding Staging and Committing
When working with git version control, commits follow a two-step process:
- Staging changes using
git add
- Recording snapshots with
git commit
This approach allows precise control over which modifications become part of your commit, supporting granular tracking in software development workflow.