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

Data loss when using "git stash -u" and ignored content in directories

From
Ulrich Buchgraber <ulrich.b@gmx.at>
Date
Apr 14, 2016, 09:16 UTC
Message-ID
<CAGxq=N-n5Vt-L4iaU2AyqYbH7oA-XcERx+oUWuSOj+rD2=MhLA@mail.gmail.com>
Hello,

A "git stash -u" cleans all untracked files (after storing them), and normally does not clean ignored files.

But: It cleans ignored files _within_ a directory, when the directory
itself is not ignored, but its content (e.g. a "dir/*" ignore filter).

The bug seems to be that in the cleanup phase of "git stash -u" Git immediately deletes untracked directories without checking if there are ignored files in there.

See the following reproduction sample. The last "ls" command shows that the file "ignored_dir_with_star/ignored.txt" is lost.

    git init
    mkdir ignored_dir && touch ignored_dir/ignored.txt
    mkdir ignored_dir_with_star && touch ignored_dir_with_star/ignored.txt
    echo "/ignored_dir" >> .gitignore
    echo "/ignored_dir_with_star/*" >> .gitignore
    git add .gitignore
    git commit -m "added ignores"
    touch untracked.txt
    ls -R
    # => Output:
    # .:
    # ignored_dir/  ignored_dir_with_star/  untracked.txt
    #
    # ./ignored_dir:
    # ignored.txt
    #
    # ./ignored_dir_with_star:
    # ignored.txt
    git stash -u
    git stash pop
    ls -R
    # => Output:
    # .:
    # ignored_dir/  untracked.txt
    #
    # ./ignored_dir:
    # ignored.txt

Note that there is no data loss when instead using "git stash" or "git stash -a".

(Tested with Git 2.8.1 on Ubuntu and Git for Windows version 2.8.1.windows.1.)
Ulrich
Message 1 of 1 in “Data loss when using "git stash -u" and ignored content in directories”
  1. Ulrich BuchgraberApr 14, 2016

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.