Command

// gat find

How to Find Lost Git Commits and Recover Deleted Branches

Search through your git history, find lost commits, recover deleted branches, and restore work that seems to be gone forever.

// Video Short

Quick Search
gat find -t "bug fix"

Search for commits containing specific text in the message

Lost Commits
gat find -t "search term"

Find commits by searching commit messages, hashes, or content

What Does gat find Do?

The gat find command provides powerful search capabilities for your Git repository, helping you locate commits, branches, and changes that might otherwise be difficult to find.

Search capabilities:

  • Commit messages: Search by text content in commit messages
  • Author search: Find commits by specific authors
  • Date ranges: Search commits within specific time periods
  • Lost commits: Find commits that are no longer on any branch

Common Recovery Scenarios

Accidentally Deleted Branch
# Find the last commit from deleted branch
gat find -t "feature/deleted-branch"
# Recover the branch
git checkout -b feature/recovered <commit-hash>

Recover a branch that was accidentally deleted by finding its last commit.

Lost After Force Push
# Find commits lost after force push
gat find -t "your-email@example.com"

Find and recover commits that were lost after a force push operation.

Find Specific Changes
# Search for commits mentioning a bug fix
gat find -t "fix bug #123"

Use regex patterns to find commits related to specific issues or features.

How to Find Lost Commits Using Git Reflog

git reflog keeps a local record of where your HEAD and branch references have been. This is usually the fastest way to find lost commits:

git reflog

This shows a list of recent commits you've visited, even if they're no longer in any branch.

Example Output:

a1b2c3d HEAD@{0}: commit: Add new feature
e4f5g6h HEAD@{1}: checkout: moving from main to feature-branch
i7j8k9l HEAD@{2}: commit: Fix bug in login

Find the commit hash you want, then check it out:

git checkout a1b2c3d

How to Search for Commits by Message

Search by Commit Message

git log --all --grep="keyword"

Search by Hash Fragment

git log --all --grep="a1b2c3"

Search in All Branches

git log --all --oneline --grep="bug fix"

How to Find Commits by Author or Date

Find Commits by Author

git log --all --author="John Doe"
git log --all --author="john@example.com"

Find Commits by Date Range

git log --all --since="2024-06-01" --until="2024-06-30"
git log --all --since="1 week ago"

Combine Author and Date

git log --all --author="Alice" --since="2024-01-01"

How to Find Unreachable Commits

If the commit isn't in any branch but still exists in the object database:

git fsck --lost-found

This will list dangling commits that are no longer referenced by any branch or tag.

Example Output:

dangling commit a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0
dangling commit b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1

You can inspect these commits with:

git show a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0

How to Find Commits by File Changes

Find Commits That Modified a Specific File

git log --all --follow -- filename.txt

Find Commits That Added or Removed Specific Code

git log --all -S "function_name"
git log --all --grep="variable_name"

Find Commits in a Specific Branch

git log branch-name --oneline
git log origin/main --grep="keyword"

How to Recover Lost Commits

Create a New Branch

git branch recovered-branch a1b2c3d

Cherry-pick the Commit

git cherry-pick a1b2c3d

Reset to the Commit (if safe)

git reset --hard a1b2c3d

Advanced Search Techniques

Search Commit Content (not just message)

git log --all --grep="pattern" --all-match

Find Merge Commits

git log --all --merges --oneline

Find Non-merge Commits Only

git log --all --no-merges --oneline

Search with Regular Expressions

git log --all --grep="fix.*bug" --extended-regexp

Frequently Asked Questions

How do I find a commit in git?

Use `git log --grep="keyword"` to search by message, or `git reflog` to see recently accessed commits.

How do I find lost commit in git?

Check `git reflog` first for recently accessed commits, then `git fsck --lost-found` for unreachable commits.

How do I search for commits in git?

Use `git log --all --grep="search term"` to search commit messages across all branches.

How do I recover lost commits?

First find the commit hash using reflog or fsck, then create a branch: `git branch recovery <hash>`.

How to find commit by message git?

Use `git log --all --grep="message text"` to search commit messages across all branches.

How do I recover lost commits?

First find the commit hash using reflog or fsck, then create a branch: `git branch recovery <hash>`.

How do I find deleted commits?

Check `git reflog` for recently deleted references, or use `git fsck --lost-found` to find unreachable commits.

How to find commit by hash git?

Use `git show <hash>` for a full hash, or `git log --all --grep="<partial-hash>"` for partial matches.

Recovery Time Limit

Git keeps unreachable commits for about 30 days by default. After that, they may be permanently removed by garbage collection. Act quickly when recovering lost work!

Simplify with gat find

While Git provides powerful tools to find and recover lost commits, the process involves multiple commands and can be overwhelming, especially when you're under pressure to recover important work. gat find simplifies this entire workflow:

gat find -t "search term"

What gat find does for you:

  • Searches everywhere at once - Checks reflog, all branches, and unreachable commits automatically
  • Intelligent matching - Finds commits by message, hash, author, or date with fuzzy matching
  • Interactive results - Shows all matches with easy selection and preview
  • Safety first - Never modifies your repository until you confirm
  • Clear explanations - Shows where each commit was found and why it was lost

Instead of remembering multiple commands (git reflog,git log --all --grep,git fsck --lost-found,git branch recovery) and piecing together the search manually, gat find does it all intelligently.

Ready to never lose commits again?