Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vscode search for a text only in git changes

Before to publish branch sometimes I want to search for a specific keyword to ensure I have fixed it correctly everywhere. The problem is, I want to search it only in changes not for a whole project.

Is it possible?

like image 628
b00sted 'snail' Avatar asked Nov 15 '19 11:11

b00sted 'snail'


People also ask

How do you search for text in VS Code?

Search across files. 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.

How do I filter search in VS Code?

You can filter the currently visible files in the File Explorer. With the focus on the File Explorer, press Ctrl/Cmd+F to open the tree Find control and type part of the file name you want to match.

How do you search for keywords in VS?

Ctrl + Shift + F – Find in Solution Sometimes you want to search across your entire solution.

How do you search for the same word in VS Code?

Ctrl + Shift + L to select all occurrences of current selection.


2 Answers

As AsGoodAsItGets pointed out in one of the comments there is a feature request pending on VS Code github which will allow us to do that.

In the meantime I have a workaround:

  1. Close all open files
  2. Open Source Control

enter image description here

  1. Right click on Changes and choose Open changed files. Note that it will open also deleted files.

enter image description here

  1. Go to Search and select Search only in Open Editors

enter image description here

Not ideal, but that's how I search for my console.log leftovers ;)

like image 146
Buszmen Avatar answered Oct 07 '22 18:10

Buszmen


Refer these screenshots. You can search in Open files easily.enter image description here

enter image description here

Also you can use File to include feature

enter image description here enter image description here

If you want to find all historical commits where commit message contains given word, use

$ git log --grep=word

If you want to find all commits where "word" was added or removed in the file contents (to be more exact: where number of occurences of "word" changed), i.e. search the commit contents, use so called 'pickaxe' search with

$ git log -Sword

In modern git there is also

$ git log -Gword

to look for differences whose added or removed line matches "word" (also commit contents).

Note that -G by default accepts a regex, while -S accepts a string, but can be modified to accept regexes using the --pickaxe-regex.

like image 40
Kunal Vohra Avatar answered Oct 07 '22 19:10

Kunal Vohra