threads / discuss / 50752

protect .git folder/files from grep/sed commands

Subject: protect .git folder/files from grep/sed commands

## tl;dr

2 messages between Mar 16, 2019 and Mar 16, 2019.

replies: 1people: 2as markdown or json

Dimitri Joukoff· Mar 16, 2019, 01:37 UTC · lore
When performing global changes in a project/tree using a command like:
grep -r "search" | xargs -I {} sed -i '' s/search/replace/g

there exists the possibility that this command will alter data in .git folder. Using GNU grep, it is possible to use --exclude '/.*"' to avoid the .git folder, but this flag is not available on BSD grep (i.e. MacOS).

Maybe git and the .git folder within a repository should be configured to use a separate user account, and then the .git folder would have its permissions set to 600?

SZEDER Gábor· Mar 16, 2019, 01:51 UTC · re: Dimitri Joukoff · lore

Re: protect .git folder/files from grep/sed commands

On Sat, Mar 16, 2019 at 01:37:39AM +0000, Dimitri Joukoff wrote:
Show 7 quoted lines
> When performing global changes in a project/tree using a command like:
> 
> grep -r "search" | xargs -I {} sed -i '' s/search/replace/g
> 
> there exists the possibility that this command will alter data in .git
> folder.  Using GNU grep, it is possible to use --exclude '/.*"' to avoid
> the .git folder, but this flag is not available on BSD grep (i.e. MacOS).
Try 'git grep "search" | ...'

← back to recent threads