Question

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?

 46  11558  46
1 Jan 1970

Solution

 50

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 ;)

2021-04-12

Solution

 7
  1. Open the terminal by typing ^, using the View > Terminal menu option, or running the View: Toggle Integrated Terminal command.
  2. Run git diff BRANCH1..BRANCH2 -G REGEX. Replace BRANCH1 with the branch to compare against, BRANCH2 with the current branch, and REGEX with a regular expression of the keyword(s) you're searching.

If you want to see the results in a VSCode editor rather than in the intergrated terminal, append | code - to the git diff command.

2020-06-17