GIT: I want to unstage all files matching a certain pattern

后端 未结 8 665
深忆病人
深忆病人 2021-01-04 20:52

I would like to run

git reset *.foo

but this errors out.

I think I need to use a pipe, but I\'m not sure how to do this.

Th

相关标签:
8条回答
  • 2021-01-04 21:18

    If you are using Powershell the following will work.

    gci -re -in *foo | %{ git reset $_ } 
    
    0 讨论(0)
  • 2021-01-04 21:21

    If you want to checkout (undo changes) of unstaged modified files matching a given pattern, 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've only tested this with M modified files. YMMV if you have renamed/deleted/conflicted files as well.

    0 讨论(0)
提交回复
热议问题