Git Commit Essentials
Understanding Git Commits in Version Control System
Git commits are fundamental to code tracking and repository management. A commit represents a specific snapshot of your project at a particular point in time, capturing changes made to files and directories.
Basic Commit Structure
graph LR
A[Working Directory] --> B[Staging Area]
B --> C[Git Repository]
Commit Component |
Description |
Commit Hash |
Unique identifier for each commit |
Author |
Person who made the changes |
Timestamp |
Date and time of commit |
Commit Message |
Descriptive text explaining changes |
Creating Your First Git Commit
To create a commit in Ubuntu 22.04, follow these steps:
## Initialize a new Git repository
git init my-project
cd my-project
## Create a sample file
echo "Hello, Git Commit!" > README.md
## Stage the file
git add README.md
## Commit with a descriptive message
git commit -m "Initial project setup with README"
Commit Best Practices
Effective commits should:
- Be atomic (represent a single logical change)
- Have clear, concise messages
- Include relevant context about the modification
Viewing Commit History
## List all commits
git log
## Show detailed commit information
git show <commit-hash>