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

后端 未结 8 664
深忆病人
深忆病人 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 20:59
    for i in `git status --porcelain | grep '^D.*\.foo$' | sed 's/^D \+//'`; do
        git reset HEAD "$i"
        git checkout "$i"
    done
    
    0 讨论(0)
  • 2021-01-04 21:01

    In a Git GUI application like SmartGit I would filter the displayed files by the pattern *.foo, press Ctrl+A to select all the filtered files and invoke the Unstage command.

    0 讨论(0)
  • 2021-01-04 21:02

    White space in filename was causing problems using the git diff approaches but the following worked:

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

    Execution is verbose if there are many files to be unstaged.

    0 讨论(0)
  • 2021-01-04 21:08

    Simply use git reset *mypattern*

    EDIT: Also try git restore, but be VERY careful as it seems to be bugged at the time of writing.

    0 讨论(0)
  • 2021-01-04 21:14

    E.g. I want to match all "migrations" in path.

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

    0 讨论(0)
  • 2021-01-04 21:16

    This should work in cygwin and unix env

    git reset $(git diff --name-only --cached | grep *.foo)
    
    0 讨论(0)
提交回复
热议问题