Skip to content

Instantly share code, notes, and snippets.

@sfdcale
Created May 22, 2025 04:00
Show Gist options
  • Save sfdcale/ad55d289392425ae02d49d8b73e254cc to your computer and use it in GitHub Desktop.
Save sfdcale/ad55d289392425ae02d49d8b73e254cc to your computer and use it in GitHub Desktop.
πŸ” Find the first merge commit on the mainline that changed a file
git log -1 --merges --ancestry-path <commit-A>..HEAD -- path/to/file

βœ… When to use:

Use this to identify the first merge commit on the mainline (first-parent path) from <commit-A> to HEAD that touched a specific file. Especially useful when a line disappears due to merge conflict resolution and isn't visible with -S or -G.


🧩 Flag breakdown:

  • git log β€” View commit history
  • -1 β€” Return only the most recent matching commit
  • --merges β€” Filter to merge commits only
  • --ancestry-path <A>..HEAD β€” Follow only the mainline ancestry (parent chain) from A to HEAD
  • -- path/to/file β€” Limit results to commits that changed the specific file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment