Git Commit Basics
Understanding Git Version Control
Git is a distributed version control system that allows developers to track code changes efficiently. In the context of git version control, commits represent specific snapshots of your project at a given point in time.
Core Commit Concepts
A commit captures the state of your project with a unique identifier, including:
- Changes made to files
- Author information
- Timestamp
- Commit message
graph LR
A[Working Directory] --> B[Staging Area]
B --> C[Git Repository]
C --> D[Commit History]
Basic Commit Commands
Command |
Description |
Usage |
git add |
Stage changes |
git add filename.txt |
git commit |
Create a snapshot |
git commit -m "Descriptive message" |
git status |
Check repository status |
git status |
Practical Example
## Initialize a new git repository
mkdir project
cd project
git init
## Create a sample file
echo "Hello, Git!" > README.md
## Stage the file
git add README.md
## Commit with a meaningful message
git commit -m "Initial project setup with README"
## View commit history
git log
This example demonstrates the fundamental workflow of creating, staging, and committing changes in a git version control environment, helping developers track code modifications systematically.