-1

I have a file .vscode/settings.json that's listed under .gitignore. Thus git stash will skip stashing it. This causes the following error when I check out another branch

error: Your local changes to the following files would be overwritten by checkout:
    .vscode/settings.json

This happens even if I issue git stash --all. Even if I temporarily comment out the file path in .gitignore, this seems to not work since stashing will also stash the change to .gitigore, thereby nullifying the commenting out.

Why isn't git stash --all ignoring the .gitignore file? What's the best way to stash a gitignored file?

John Jiang
  • 827
  • 1
  • 9
  • 19
  • "Ignored" means "not under Git's control". Git is essentially blind to the existence of this file. It makes no sense to speak of stashing such a file. A stash is a commit; you've told Git _ not_ to commit this file. – matt Aug 09 '22 at 02:54
  • 1
    You could say `git stash push -- myfile` but then only this one file would be stashed. Still, perhaps that would do. But it sounds like what's really needed is to get clear on your policy towards this file. Needing to stash an ignored file seems like a misunderstanding. – matt Aug 09 '22 at 03:01
  • The error message you're getting indocates that `.vscode/settings.json` is *tracked*, and a tracked file is never ignored, regardless of whether it's listed in `.gitignore`. I think you're asking [this Frequently Asked Git Question](https://git.wiki.kernel.org/index.php/Git_FAQ#How_do_I_tell_Git_to_ignore_tracked_files.3F). – torek Aug 09 '22 at 03:10

1 Answers1

-1

It turns out I did git update-index --skip-worktree .vscode/settings.json at one point. Undoing this operation revealed the file under git status -uno.

John Jiang
  • 827
  • 1
  • 9
  • 19