Git: how to use stash -p to stash specific files?

git stash apply specific file
git stash specific files
git stash stack overflow
git stash -p
git stash pop specific
git stash message
git stash name
git stash apply not working

I'm trying to figure out how to stash two specific files among many uncommitted changes.

This very promising answer, Stash only one file out of multiple files that have changed with Git?, doesn't show the usage and I'm having trouble working it out.

The following doesn't work and the man page isn't very helpful (it appears to talk about terminal output, not actually stashing). I want to stash application.conf and plugins.sbt and then commit everything else.

app (master)$ git status
On branch master
Your branch is ahead of 'origin/master' by 29 commits.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   views/mobile/blog.scala.html
        modified:   views/mobile/slideshow.scala.html
        modified:   ../public/css/mobile/styles.css

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

        both modified:   ../conf/application.conf

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:   ../project/plugins.sbt

app (master)$ git stash -p ../conf/application.conf ../project/plugins.sbt 

usage: git stash list [<options>]
   or: git stash show [<stash>]
   or: git stash drop [-q|--quiet] [<stash>]
   or: git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
   or: git stash branch <branchname> [<stash>]
   or: git stash [save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
                       [-u|--include-untracked] [-a|--all] [<message>]]
   or: git stash clear


git stash --patch

git will then show a dialog like the following, for every hunk in your possible commit:

diff --git files over files
index e69de29..ac4f3b3 100644
--- a/file.txt
+++ b/file.txt
@@ -0,0 +1 @@
+you did awesome stuff!
Stash this hunk [y,n,q,a,d,/,e,?]?

A hunk is a coherent diff of lines as git-diff produces it. To select a single file you'll have to decline adding hunks as long as you reach that file, then you might add all hunks from that file.

You're also able to choose a single hunk by answering the question with yes. If the hunk seems to be too big, you even might split it. It is also possible to edit the current hunk.

Using the --patch-option is possible on different git commands (f.e. stash, commit and add).

This is the detailed explanation of the --patch-function, which i grabbed from the developers documentation:

This lets you choose one path out of a 'status' like selection.
After choosing the path, it presents the diff between the index
and the working tree file and asks you if you want to stage
the change of each hunk.  You can select one of the following
options and type return:

   y - stage this hunk
   n - do not stage this hunk
   q - quit; do not stage this hunk or any of the remaining ones
   a - stage this hunk and all later hunks in the file
   d - do not stage this hunk or any of the later hunks in the file
   g - select a hunk to go to
   / - search for a hunk matching the given regex
   j - leave this hunk undecided, see next undecided hunk
   J - leave this hunk undecided, see next hunk
   k - leave this hunk undecided, see previous undecided hunk
   K - leave this hunk undecided, see previous hunk
   s - split the current hunk into smaller hunks
   e - manually edit the current hunk
   ? - print help

How to unstash only certain files?, As mentioned below, and detailed in "How would I extract a single file (or changes to a file) from a git stash?", you can apply use git checkout or  When you feel that you no longer require to keep a stash entry in the stash-list, you can delete the stash by executing git stash dropcommand, which will remove the latest stash entry from the stash list. You can also mention the stash-index used like before to remove a particular stash entry from the stash-list.

Use git stash -p without arguments. You will then be able to interactively select changes that you want to stash:

diff --git a/test b/test
index acbd8ae..662d47a 100644
--- a/test
+++ b/test
@@ -10,6 +10,7 @@ test
+    test
Stash this hunk [y,n,q,a,d,/,e,?]?

Unfortunately it's not possible to select files, only hunks.

How can I git stash a specific file?, Since git is updated to 2.1.3, we have a command to save a specific path to stash. Syntax: git stash push <path>. For your query use. git stash  As Ben pointed out, you may use git stash path/to/file path/to/other/file to stash specific files. Another handy tip is that git provides very detailed man pages for each sub-command! However, these pages are somewhat tricky to find if you don't know the secret: Use man git-<name-of-subcommand>!

In the most recent versions of Git (> v2.13) you can stage the specific files you want to stash using

git stash push -- <pathspec>

For example, if you stage the specific files you want to stash you can use this command to specifically stash only those file(s):

git stash push -- example/file/path/and/file.html

You can save yourself some typing by using a globbing pattern to stash the specific files in the path

git stash push -- **/path/**

You'll want to stage only the files you want to stash since any other staged files will be stashed with the specific files, but also remain staged after stashing so if you git stash pop you would get conflicts.

Stashing and Cleaning, git stash apply On branch master Changes not staged for commit: (use "git add If the apply tries to modify a file that you've since modified, you'll get a merge  $ git stash save. This will stash all tracked files. In order to move all files, tracked or untracked, we need to use the following command, $ git stash -u. Note:-Tracked files are those files that have either been added to index or committed. To see list of such files, run the command $ git ls-files . Apply the stash

Git Stash A Specific File, git stash a specific file Sometimes you only want to stash a few files at a time. Maybe in Changes not staged for commit: (use "git add <file>. From the Git Manual (run git stash --help to see it on your own): Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.

Stash Changes – TortoiseGit – Documentation – TortoiseGit , The answer to this issue is the git stash command. Stash Apply will apply the changes of the latest stash to your working tree. happen during cherry-picking (​i.e., a file was modified in your current branch and also in the stash), please see  $ git stash pop 'stash@{1}' which will apply the changes and then immediately drop them. Finally, it is also possible to remove all the stash entries if you don’t need them any more: $ git stash clear Selecting files to stash. Command git stash save (or in short git stash) stores only the modifications made to the

How to use Git Stash, It's just reversing what you did when saving the stash (but keeping any subsequent repository changes intact). You can also be specific and pop any stash in the  What that means is if you do git stash in feature-xyz branch, you can run git stash pop in master branch, for example. This can be useful if you’ve accidentally written code on a wrong branch. Git stash is not always the best solution. There are times when it’s not wise to use git stash to