I have many changed files and would like to stash only some of the modified files.
As an example, my repository looks something like:
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: main.cpp
modified: MyClass.h
modified: MyClass.cpp
And I would like to stash MyClass.h
and MyClass.cpp
only.
I found this question but the accepted answer appears to be wrong and the most voted answer requires each hunk/file to be interactively added.
Is there an easy way to stash a specific set of files? Preferably in a single command without having to interactively select files one by one or stage/unstage things.
答案 0 :(得分:3)
I found git stash push
can be used to easily stash multiple files.
To stash the files from the example the command would be
git stash push MyClass.h MyClass.cpp
Which stashes MyClass.h
and MyClass.cpp
but leaves main.cpp
alone.
Found in an edit to this answer