0

I need to search a long list of git hash ids for a short id which added a file.

For the purpose I checked what was the hash of an old commit which added a file script.js, which I successfully do like:

git log --diff-filter=A -- script.js

, but it spits out the long hash and I want the short instead. I found out that to get the short hash, I can do as follows: git rev-parse --short long, then I finally have the short.

Then I do git rebase -I --root to find my short id, but the list is circa 200 lines long. What is a good way to search for my id through this output?

torek
  • 448,244
  • 59
  • 642
  • 775
apingaway
  • 33
  • 1
  • 1
  • 17
  • 3
    If you're using an interactive rebase, doesn't your editor have a search function? If you're using defaults, you'll be in Vim, so you can type `/` and then the hash you're looking for. – joanis Oct 27 '22 at 22:54
  • 1
    Hash IDs are unfriendly. If at all possible, use good commit messages with good subjects so that you can search using the subject instead of the raw hash ID. That said, as @joanis notes, your editor should have a search function. Some other minor points: rebase can format the hash IDs longer, if you want; `git log` can shorten the hash IDs for you, if you want; and the short form is made by dropping the tail part of the long form, so it's easy to snip off extra junk with cut-and-paste. – torek Oct 28 '22 at 02:26

1 Answers1

0

There are several ways:

  1. You can do git rebase -I --root >> file.txt, then ctrl/cmd + f the file, similar to what joanis has already suggested in the comments above, but in VIM.
  2. pbcopy can also be used as here described
  3. git grep <stuff to search for without the brackets of course>

GL

apingaway
  • 33
  • 1
  • 1
  • 17