Git Commit Basics
Understanding Git Commits
Git commits are fundamental to version control, representing snapshots of your project at specific points in time. Each commit captures changes made to files, along with metadata such as author, timestamp, and a commit message.
Basic Commit Structure
graph LR
A[Working Directory] --> B[Staging Area]
B --> C[Repository]
Key Components of a Commit
Component |
Description |
Example |
Commit Hash |
Unique identifier |
a1b2c3d4e5f6 |
Author |
Person making changes |
John Doe <[email protected]> |
Timestamp |
Date and time of commit |
2023-06-15 14:30:45 |
Commit Message |
Description of changes |
Add user authentication feature |
Creating a Commit in Ubuntu
To create a commit, follow these steps:
- Stage your changes:
git add file_name.txt
## Or stage all changes
git add .
- Commit with a message:
git commit -m "Your descriptive commit message"
Best Practices
- Write clear, concise commit messages
- Commit frequently
- Group related changes in a single commit
- Use imperative mood in commit messages
Common Commit Commands
## View commit history
git log
## View detailed commit information
git show commit_hash
## Amend the most recent commit
git commit --amend
By understanding these Git commit basics, you'll be well-prepared to manage your project's version control effectively with LabEx's comprehensive learning resources.