git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Apparent bug in 'git stash push <subdir>' loses untracked files

From
RPReid Price <reid.price@gmail.com>
Date
Dec 13, 2017, 17:32 UTC
Message-ID
<CA+HNv10i7AvWXjrQjxxy1LNJTmhr7LE4TwxhHUYBiWtmJCOf_A@mail.gmail.com>

When running 'git stash push <subdir>' if there are both tracked and untracked files in this subdirectory, the tracked files are stashed but the untracked files are discarded.

I can reproduce this on my system (OSX, git 2.14.1) by running the below script as

    bash -x ./stashbug.sh &> output.txt

I could not find this indicated anywhere as an existing issue by performing generic searches, apologies if this is known.

  -Reid
Contents of stashbug.sh
------------------------
    #!/bin/sh
    uname -a
    git --version
    mkdir -p stashbug
    cd stashbug
    git init
    mkdir dir
    touch dir/tracked
    git add dir/tracked
    git commit -m 'initial'
    tree; git status
    mkdir dir/untracked_dir
    touch dir/untracked_dir/casualty1
    touch dir/casualty2
    echo 'contents' > dir/tracked
    tree; git status
    git stash push dir/
    git stash show -v
    tree; git status
    git stash pop
    tree; git status
------------------------
Resulting output.txt
---------------------
    + uname -a
    Darwin Reids-MacBook-Pro.local 15.6.0 Darwin Kernel Version
15.6.0: Tue Apr 11 16:00:51 PDT 2017;
root:xnu-3248.60.11.5.3~1/RELEASE_X86_64 x86_64
    + git --version
    git version 2.14.1
    + mkdir -p stashbug
    + cd stashbug
    + git init
    Initialized empty Git repository in /Users/reid/git/stashbug/.git/
    + mkdir dir
    + touch dir/tracked
    + git add dir/tracked
    + git commit -m initial
    [master (root-commit) 895197e] initial
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 dir/tracked
    + tree
    .
    └── dir
        └── tracked
    1 directory, 1 file
    + git status
    On branch master
    nothing to commit, working tree clean
    + mkdir dir/untracked_dir
    + touch dir/untracked_dir/casualty1
    + touch dir/casualty2
    + echo contents
    + tree
    .
    └── dir
        ├── casualty2
        ├── tracked
        └── untracked_dir
            └── casualty1
    2 directories, 3 files
    + git status
    On branch master
    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:   dir/tracked
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
        dir/casualty2
        dir/untracked_dir/
    no changes added to commit (use "git add" and/or "git commit -a")
    + git stash push dir/
    Saved working directory and index state WIP on master: 895197e initial
    + git stash show -v
    diff --git a/dir/tracked b/dir/tracked
    index e69de29..12f00e9 100644
    --- a/dir/tracked
    +++ b/dir/tracked
    @@ -0,0 +1 @@
    +contents
    + tree
    .
    └── dir
        └── tracked
    1 directory, 1 file
    + git status
    On branch master
    nothing to commit, working tree clean
    + git stash pop
    On branch master
    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:   dir/tracked
    no changes added to commit (use "git add" and/or "git commit -a")
    Dropped refs/stash@{0} (93ceee344b947ecd8a27a672e3aedd2b2e1acc99)
    + tree
    .
    └── dir
        └── tracked
    1 directory, 1 file
    + git status
    On branch master
    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:   dir/tracked
    no changes added to commit (use "git add" and/or "git commit -a")
---------------------
Next: Igor Djordjevic
Message 1 of 10 in “Apparent bug in 'git stash push <subdir>' loses untracked files”
  1. Reid PriceDec 13, 2017
  2. Igor DjordjevicDec 13, 2017
  3. Thomas GummererDec 13, 2017
  4. Igor DjordjevicDec 13, 2017
  5. Thomas GummererDec 13, 2017
  6. Junio C HamanoDec 16, 2017
  7. Thomas GummererDec 17, 2017
  8. Junio C HamanoDec 18, 2017
  9. Thomas GummererJan 5, 2018
  10. stash: don't delete untracked files that match pathspecThomas Gummerer, Jan 6, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.