Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How can I determine the filename where a given identifier was added or removed?

Tags:

git

I find out that a certain CSS class .razmatazz is used in an HTML file, but this identifier is not in any of the present CSS files. That explains the incorrect presentation, which I've been "kicking forward" for some time.

I can find all the commits in which this identifier was either added or deleted by running

> git log -S razmatazz --source --all
847d9d8 Thu Jun 25 10:05:07 2018 Joe C helpful commit message.
9384843 Wed May 20 14:10:34 2018 Joe C ever more helpful commit message.
2093483 Mon Apr 15 11:15:51 2018 Joe C yet another great message.

but meanwhile I've been merging/unmerging/renaming my CSS files, hence I do not know the CSS filename.

How can I determine the filename where a given identifier was added or removed?

Since the "pickaxe" git option doesn't say whether the identifier was added or deleted, I would try both the hashes found and their predecessors

git show 847d9d8:/path/to/file
git show 847d9d8^:/path/to/file
git show 9384843:/path/to/file
git show 9384843^:/path/to/file
git show 2093483:/path/to/file
git show 2093483^:/path/to/file

to retrieve the missing definition.

like image 460
Calaf Avatar asked Dec 04 '18 00:12

Calaf


1 Answers

-S or -G can actually by combined with other options :

  • --name-only and --name-status will only list files where said pattern was selected,

  • -p|--patch will only show you the diff of said files (the complete diff of these files though, it will not limit the diff to only chunks which impact the -G / -S search criteria)


So : depending on what you want, add -p or --name-status to your git log -S razmattaz command.

like image 65
LeGEC Avatar answered Oct 11 '22 16:10

LeGEC