How to search for a block of code in general

My files have

.settings { } .field { margin-bottom: 1em; } 

I want to know when

 .settings { } 

.

I know if I want to search for a single line of code , I do git log -S".settings {" .

But here I want to search

 .settings { } 

overall i tried

 git log -S".settings {\r}" confirm.less.css git log -S".settings {\n}" confirm.less.css git log -S".settings {\r\n}" confirm.less.css 

but it doesn’t extract anything.

How do I search for a block of code as a whole that contains new string characters?

+5
source share
2 answers

There were several problems for this to work properly.

First, I think you need to handle the { } metacharacters in your RegEx, escaping them and enabling extended mapping with --pickaxe-regex . I also used plain \s* to greedily match any space, including newlines between brackets.

Here is the resulting team that I came with

git log -S".settings \{\s*\}" --pickaxe-regex confirm.less.css

Which returned a commit containing the first appearance.

+1
source

Try

 git log -L '/^.settings {/,+1':path/to/it 

This will give you the entire update history for this range, but the oldest one will be what you want.

+3
source

Source: https://habr.com/ru/post/1273585/


All Articles