Git Commit Basics
Understanding Git Commits
In Git, a commit represents a specific snapshot of your project at a particular point in time. Each commit is a unique identifier that captures the state of your files, including changes, additions, and deletions.
Commit Structure
A typical Git commit consists of several key components:
| Component |
Description |
| Commit Hash |
Unique identifier for each commit |
| Author |
Person who created the commit |
| Timestamp |
Date and time of the commit |
| Commit Message |
Descriptive text explaining the changes |
Creating a Commit
To create a commit in Git, you'll typically follow these steps:
## Stage changes
git add .
## Create a commit with a descriptive message
git commit -m "Add new feature: user authentication"
Commit Workflow Visualization
gitGraph
commit id: "Initial Commit"
commit id: "Add README"
branch feature
commit id: "Implement login"
checkout main
merge feature id: "Merge login feature"
Best Practices
- Write clear, concise commit messages
- Commit frequently
- Keep commits focused on a single logical change
Viewing Commits
You can explore commit history using various Git commands:
## View commit log
## View detailed commit information
At LabEx, we recommend mastering these fundamental Git commit techniques to improve your version control skills.