Sublime Forum

Find inside a commit


Let say I’m looking at a commit, how can I search for a word inside that specific commit?

Normally I would do:

git show

and search with /

1 Like


Hey @FrancoisGervais, welcome to the community!
You can hit control-f, type commit: and the commit hash and content: with your search text. You can also type path: or file: to make your search more specific.

1 Like


That’s perfect,

Any way I can reference the current commit I’m on? I would have though commit:HEAD but it doesn’t seem to work.



One way to do this would be to use the context menu to copy the commit hash of the commit that you’re viewing (for example from the “three dots” menu that appears in the commit details box) so that you can paste it into the commit: field.

It might be possible to craft a key binding that would do that in a single step; I’m not sure. There’s a variable that expands out to the current commit hash, so I would think that you could craft an argument to open the find panel with that pre-populated.

There may also just be such a key already that I’m not aware of at the moment. :slight_smile:



Below would be how, but I’m not sure how useful it’ll end up being. The contents: section will only search the changed text in the commit (not near/within-hunk or anywhere else in the file) and worst of all, the search results will include the entire file changes, not just the matching hunk(s).

Put in File.sublime-menu and/or Diff Context.sublime-menu for right-click support (it will be available in the working copy, but won’t work correctly due to the missing commit hash):

        "caption": "Find changes in File...",
        "command": "search", "args": { "query": "path:\"$path\" and commit:$commit and contents:search" }

How to search in current file changes?

Thank you all for the replies



I came here to basically ask this same question, and unfortunately the workarounds suggested so far don’t seem to be sufficient to address the meat of the problem: Finding what contains something isn’t the same as finding where it is inside that something.

contents:__string__ search works great, for locating commits that modify a certain string in the code. But it doesn’t help that much when the commit that comes up is a big merge, an import of a new vendor release, or similar megacommit. (Exactly the situation I found myself in, IOW.) In those situations, if you’re lucky you can switch through the different tabs for each matching file (first time those tabs have really come in handy for me, but I now appreciate their usefulness), but sometimes even the changes in each file are large and it’s not any help at all. Ultimately, knowing a match is “somewhere in here” becomes completely useless, for sufficiently large values of “here”.

I ended up copying the commit hash for the match that came up, going into a shell window, and running git show <paste> to pull up the diff. Then I searched again for my string in the output, just as @FrancoisGervais said.

Obviously, something’s a bit broken, if that’s what it takes to get the desired results.

There’s a reason “Find in page” is a separate operation from “Search”, in web browsers. …Where do we file actual feature requests, for SM? …Oh, right. The 'hub.

Hmmm, never mind — it’s there (#429), and another for the three-way conflict resolution view (#512).