Search code examples
gitsyntaxgit-stashgit-add

Is it possible to add (stash) several file types in git?


Assume I have

git status
...
Changes not staged for commit:
        modified:   A.R
        modified:   B.Rmd
        modified:   C.txt
...

Is there a way to do the following:

git add *.Rmd OR *.R

or

git stash *.Rmd OR *.R

? I can't find it in the docs for add or stash.


Solution

  • git add "*.R"
    

    works fine (with quotes). In the doc, it's mentioned as the <pathspec> you can give as a parameter.

    For stash, you'll have to explicitly use the (usually implied) push :

    git stash push "*.R"
    

    The doc mentions :

    When pathspec is given to git stash push, the new stash entry records the modified states only for the files that match the pathspec.

    (Edit after comments) And if you need both types, just give multiple pathspecs like this :

    git add "*.R" "*.Rmd"
    git stash push "*.R" "*.Rmd"