Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does git delete ignored files under `directory/*` but not under `directory/`

Tags:

git

As mentioned in this post

To put it another way, if you have the following in your .gitignore:

/my-ignored-directory/*

Then you’re screwed – after a git stash save -u, my-ignored-file.txt will be gone (and sorry, it’s not in the stash you just created either). Break out the undelete packages and hope for the best. Alternatively, if you have the following in your .gitignore:

/my-ignored-directory

Then you’re golden – no worries, kick back, relax, my-ignored-file.txt will stay exactly where it was prior to the git stash save -u.

Why is this difference? I'm also wondering if no files will be deleted if in my .gitignore file I have /my-ignored-directory/ (with trailing slash)?

like image 665
Max Koretskyi Avatar asked Oct 30 '22 08:10

Max Koretskyi


1 Answers

Results of both you examples will be the same, ignored files are gone. There is of course solution for it described in documentation:

If the --include-untracked option is used, all untracked files are also stashed and then cleaned up with git clean, leaving the working directory in a very clean state. If the --all option is used instead then the ignored files are stashed and cleaned in addition to the untracked files.

Git internally calls git clean -d to put working directory in a very clean state.

Command that you want is:

git stash --include-untracked --all 
like image 105
s7anley Avatar answered Nov 08 '22 03:11

s7anley