A simple command line tool to search for commit-message or file-content in a git repository to retrieve the corresponding git hash.
npm install git-grep-cliA simple command line tool to search for commit-message or file-content in a git repository to retrieve the corresponding git hash.
It is more convenient and powerful than the native API provided by git, and can help you find files better (including git's --lost-found objects).
From another point of view, git-grep-cli provides stronger "regret medicine" for git, which can help you quickly find lost files (provided that the lost files have been added to the git staging area; for unreachable objects, it must be the changes within two weeks, because the default value of git gc --prune is two weeks ago).
You can follow these steps to execute it:
``sh`create a file
echo "hello world" > lost-file-1add it to the staging area
git add lost-file-1undo the staging area
git restore --staged lost-file-1delete the file
rm lost-file-1
Now, lost-file-1 is lost, and you want to find it back. You can use git-grep-cli to search for it:
`sh`
ggc "hello world" -t content
You will get the git-hash of lost-file-1, and then you can use git show to view the content of this file.
You can follow these steps to execute it:
`sh`create a file
echo "bye bye" > lost-file-2add it to the staging area
git add lost-file-2commit it
git commit -m "feat: add lost-git-commit"undo the commit
git reset --hard HEAD~1
You can use git-grep-cli to find it back:
`sh`find the lost git-commit record by file content
ggc "bye bye" -t contentor
find the lost git-commit record by commit message
ggc "lost-git-commit" -t message
You will get the git-hash of the lost git-commit record, and then you can use git show to view the content of this commit record. You can also use git cherry-pick to apply this commit record.
You need to install git-grep-cli globally.
Using npm:
`sh`
npm install git-grep-cli -g
Using yarn:
`sh`
yarn add git-grep-cli -g
Using pnpm:
`sh`
pnpm add git-grep-cli -g
You can use it in your terminal:
`sh`
ggc -s
- -s or --search : the search content-t
- or --type : the search type, message for git commit message, content for file content, all for both-l
- or --length : the length of the returned content
`sh``
ggc "hello world"or
ggc -s "hello world"or
ggc -s "hello world" -t messageor
ggc -s "hello world" -t content -l 50
- Support searching for commit-message and file-content
- Support searching for lost files and lost git-commit records (provided that the lost files have been added to the git staging area)
- Support specifying the length of the returned content
MIT