Issue
I am searching for the word STATIC_ASSERT
in all branches in my Git repo using this command, which I modified from here:
time git branch -a --color=never | sed -e 's/[ \*]*//' \
| grep -v -e '\->' -e '^remotes' \
| xargs -n 1 -P "$(nproc)" git grep -I "STATIC_ASSERT"
If I remove -P "$(nproc)"
then it works fine but takes 1.8 seconds.
If I add that back in, I get the exact same output, but it uses multiple processes in parallel and takes only 0.4 seconds! But, then I get this issue where the terminal stops showing typed commands, and I have to follow my instructions here to press Ctrl + C and type reset
to get the terminal back to normal.
Why does this happen? How can I fix it?
Note: it may not be repeatable in your repo. I haven't figured it out yet.
Solution
There's a hint in the top answer on that question: editors. Git uses a pager, which is sort of like an editor, so if you disable it, the issue goes away.
git --no-pager grep ...
If your output is long and you want to add back the pager, you can do it manually, for example:
git --no-pager grep --color=always ... | less
(--color=always
is because git
normally disables color when not outputting directly to a terminal.)
Answered By - wjandrea Answer Checked By - Katrina (WPSolving Volunteer)