GIT: I want to disable all files matching a specific pattern

I would like to run

git reset *.foo 

but these errors are missing.

I think I need to use the handset, but I'm not sure how to do it.

Thanks!

+9
git filepattern
source share
8 answers
 for i in `git status --porcelain | grep '^D.*\.foo$' | sed 's/^D \+//'`; do git reset HEAD "$i" git checkout "$i" done 
+8
source share

If you are using Powershell, the following will work.

 gci -re -in *foo | %{ git reset $_ } 
+6
source share

This should work in cygwin and unix env

 git reset $(git diff --name-only --cached | grep *.foo) 
+4
source share

In a Git GUI application, for example SmartGit, I would filter the displayed files according to the *.foo template, press Ctrl + A to select all the filtered files and call the Unstage command.

+2
source share

eg. I want to match all the “migrations” in the path.

git diff -name-only | grep migrations | xargs git checkout

+1
source share

If you want to check (undo changes) of uninstalled modified files that match a given template, this works:

MacOS:

 git checkout $(git st -s | sed -E 's/^.{2}//' | grep '\.foo$') 

Unix:

 git checkout $(git st -s | sed -r 's/^.{2}//' | grep '\.foo$') 

I tested this with only M modified files. YMMV if you also renamed / deleted / conflicted files.

0
source share

Spaces in the file name caused problems when using the git diff approaches, but the following worked:

 find ./ -name "*.foo" -exec git reset {} \; 

Execution is verbose if there are many files that need to be deleted.

0
source share

Just use git reset *mypattern*

0
source share

All Articles