My files has
.settings {
}
.field {
margin-bottom: 1em;
}
I want to know when
.settings {
}
was formed.
I know if I want to search one line of code, I do git log -S".settings {"
.
But here I want to search
.settings {
}
as a whole, 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 all retrun nothing.
How do I search a block of code as a whole containg new line characters?
VS Code allows you to quickly search over all files in the currently opened folder. Press Ctrl+Shift+F and enter your search term. Search results are grouped into files containing the search term, with an indication of the hits in each file and its location.
You can select blocks of text by holding Shift+Alt (Shift+Option on macOS) while you drag your mouse.
You can also block comment multiple lines of code using the characters /* */ . Tip: The characters /* */ on lines that already are already commented out are not affected when you comment and uncomment code as described above.
To comment out multiple lines in Python, you can prepend each line with a hash ( # ). With this approach, you're technically making multiple single-line comments. The real workaround for making multi-line comments in Python is by using docstrings.
Try
git log -L '/^.settings {/,+1':path/to/it
That'll get you the whole history of updates to that range, but the oldest of them will be what you want.
There was a few issues getting this to work properly.
First, I think you need to handle the {
}
metacharacters in your RegEx by escaping them, and enable extended matching with --pickaxe-regex
. I also used a simple \s*
to greedily match any space including newlines between brackets.
Here is the resulting command that I came up with
git log -S".settings \{\s*\}" --pickaxe-regex confirm.less.css
Which returned the commit containing the first appearance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With