How to search through files (using VSCode) at a previous commit stage in a local repo

I wanted to change the files to a previous commit in a repo so as to use VSCode search in files feature. Note that searching through a particular file is easy using GitHub or GitHub Desktop or GitGUI. But I could not find a search in all files of project feature in them, which is available in VSCode.

I am not confident enough about my git knowledge to go back to a previous commit stage in a live project folder, search through the files and then get back to the latest commit stage in the live project. So, to be on safe side, I made a copy of the project and in the temp copy, I wanted to change the files to the previous commit. But the copy also was linked to the remote repo and so that link had to be snapped to avoid any possible issues.

git: how to break link with remote repo

I tried to do that using GitHub Desktop and that seemed to do it but there was some confusion.
I think Git GUI also may help there using its Remote menu but I am not so sure about it.

git command line seems to be the authoritative stuff.
Ref: How to change/delete/remove an existing remote URL in Git?, https://atulbhatt98.medium.com/how-to-change-delete-remove-an-existing-remote-url-in-git-e26a88684e6f, Mar. 2021

To check whether the local repo is connected to a remote repo: git remote -v
For a repo which is connected to remote, I got this output on: git remote -v
origin  https://github.com/ravisiyer/blogapitostaticsitetest.git (fetch)
origin  https://github.com/ravisiyer/blogapitostaticsitetest.git (push)
----

The git command to remove the connection to remote repo (named origin?) is:
git remote remove origin
After that, git remote -v gave no output.

Resetting files to a previous commit

Ref: Git Reverting to Previous Commit – How to Revert to Last Commit, https://www.freecodecamp.org/news/git-reverting-to-previous-commit-how-to-revert-to-last-commit/

git log --oneline
git reset {commit-name} --hard

Specifically I ran: git reset 364e8fa --hard
for which I got the output:
HEAD is now at 364e8fa Initial commit from Create Next App
----

And now VSCode was showing the files as they were at that commit point with the exception of showing one file that I had added later on. That was not an issue for my current need. I was able to conveniently search through the files using VSCode and understand which files used certain image/icon files. Then I simply deleted the temp project copy I had made.

The above freecodecamp article covers both reset and revert. I later tried revert in another project (which was a copy of live project) and it worked as expected. I was able to view the files as they were before the commit point that was passed to revert.

Comments