3

I earlier ran git stash push -u ... to include an untracked file in the stash. Now, I've confirmed that this stash, stash@{2}, includes this untracked file (and tracked file changes). But, when I run git stash apply 2, only the tracked files get applied. (note: there were a couple of merge conflicts with some of the tracked files)

I didn't change any directory structure or replace this untracked file since this stash, so it should be able to be easily placed back where it was.

Why isn't the untracked file getting applied?

Thanks for any help!

--

Here, I applied the stash:

$ git stash apply 2
Auto-merging <file1>
CONFLICT (content): Merge conflict in <file1>
Auto-merging <file2>
CONFLICT (content): Merge conflict in <file2>

The untracked file is missing at this point, but I resolve the conflicts, then run:

$ git restore --staged .

The stash apply has been completed, but the untracked file is still missing.

Update

According to this article, it seems that this could possibly be a bug introduced between Git 2.24 and 2.33 (and git --version tells me I'm using 2.34.1). However, I'm not sure if this is very likely since I feel like this problem would have more attention, given that git 2.33 apparently released almost 2 years ago (Aug 16, 2021).

user1021
  • 61
  • 6
  • What is the output of `git stash apply 2`? – SebDieBln Jul 03 '23 at 22:56
  • Did you create the untracked file after `git stash push` deleted it? If so you need to remove it so that `git stash apply` can restore it from the stash. – SebDieBln Jul 03 '23 at 22:58
  • Are you sure the untracked file doesn't just happen to be filtered by .gitignore on the commit/branch you're trying to apply the stash on? Also: How exactly did you confirm that the file is included in the stash? `git show --stat stash@{2}^3` ? – Jay Jul 04 '23 at 05:56
  • 1
    Also, possible workaround; manually restore the untracked files from stash: `git cherry-pick --no-commit stash@{2}^3` (this will also stage the new files) or `git show --full-index stash@{2}^3 | git apply -v` – Jay Jul 04 '23 at 06:05
  • 1
    @Jay, yeah the .gitignore isn't filtering this file out. I confirmed the presence of the untracked file by comparing the outputs of `git stash show 2` and `git stash show -u 2` (the file in question only appeared from the latter). – user1021 Jul 04 '23 at 06:15

1 Answers1

2

Answer:

It turns out this was a bug in git 2.34.1. Upgrading to 2.41.0 worked for me.

Exactly what I did to resolve:

I was using WSL (Ubuntu 22.04 LTS), so in order to upgrade git past 2.34.1, I followed this article's guide, using the following commands, which left me with git 2.41.0:

sudo add-apt-repository ppa:git-core/ppa -y
sudo apt update
sudo apt install git -y

Since my working directory and staging area were clean before the unfinished git stash apply, I cleaned it with the following:

git stash push -u
git stash drop

Then, back to my original goal, I did the following, and it worked perfectly as expected:

git stash apply 2
# (resolved conflicts)
git restore --staged .
user1021
  • 61
  • 6