1. Git Reflog
Reflog tracks changes to your repository's HEAD pointer. Use it to:
- Recover lost commits:
git reflog --grep="<commit_message>"
- Explore historical actions:
git reflog show <commit_hash>
- Understand branch evolution:
git reflog branch
💡 Tip: Always enable
git config --global log.showCommitStats true
for detailed reflog analysis
2. Git Stash
Temporarily save uncommitted changes with:
git stash push -m "temporarily_saved_changes"
Retrieve stored changes using:
git stash apply
3. Git Rebase
Rebase helps create a cleaner project history:
- Interactive rebase:
git rebase -i <commit_hash>
- Squash commits:
git rebase -i HEAD~3
- Resolve conflicts:
git rebase --continue
⚠️ Warning: Rebase can rewrite history - use with caution in shared branches
4. Git Grafting
Grafting allows you to:
- Connect unrelated histories:
git graft <commit_hash>
- Create custom merge points:
git merge-base <branch1> <branch2>
- Build alternative history trees
5. Advanced Tips
- Use
git status --porcelain
for machine-readable output - Enable
git config --global status.showUntrackedFiles true
- Explore
git gc --aggressive
for repository optimization
For deeper understanding of Git workflows, visit our Git Workflow Guide.