Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git stash from VS Code fails to stash

Git stash from the Visual Studio Code - Source Control tab popup menu fails to stash.

This worked without problem for this repository about two months ago. Now it fails nearly all the time (but on rare occasions it does work.) This fails only for specific repository, for all branches in that repository. Stash still works for other projects in other repositories.

Steps to recreate failure:

  1. On source control tab, select one or more files.
  2. Right click and select Stash...
  3. Provide a stash name.

Result: the files remain in the source code list of changed files, and the new stash does not appear in the list of stashes

How can I get stash to work again, consistently (for this repo)?

Environment:

Mac Catalina 10.15.7;  
GIT: 2.29.2
VSCode: 1.50.1
Commit: d2e414d9e4239a252d1ab117bd7067f125afd80a
Date: 2020-10-13T14:53:05.704Z
Electron: 9.2.1
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Darwin x64 19.6.0Git
like image 579
Brian Cragun Avatar asked Mar 07 '26 13:03

Brian Cragun


1 Answers

  1. Make note of the files you want to stash.
  2. Copy the files you want to stash to a new directory outside of your working project. I usually just zip the /src subdirectory and move it to ~/Downloads. (If you need your file history, save the /.history directory, too.)
  3. Totally remove the entire directory and its contents. On Unix: rm -r my-project
  4. Re-clone the project. git clone https://github.com/my-project.git
  5. If you were working in a branch, re-checkout the branch you were working on in it's last committed state. git checkout my-working-branch
  6. Now restore the files you wanted to stash (and any other files that were unchanged in the branch). A diff tool like BeyondCompare is invaluable in this step. If you saved the entire directory, you can compare at the same directory level and see each file that is not in your new clone + branch.
  7. Now you are where you were when you tried to stash. The ability to stash will be restored. Stash your files.

An alternative:

  1. Rename the directory that contains your failing project. You can use Finder or File Explorer to do this. Or on Unix: mv my-project-oldname my-project-newname
  2. Follow steps 4, 5, 6 above.
like image 85
Brian Cragun Avatar answered Mar 10 '26 08:03

Brian Cragun