Your cart is currently empty!
Resolving Git “Unable to Unlink” Errors When Stashing Changes
The Problem
When attempting to stash changes using Git with untracked files, you might encounter multiple “unable to unlink” errors that look like this:
error: unable to unlink old 'CDISV2Core.dll': Invalid argument
error: unable to unlink old 'CDISV2Core.exe': Invalid argument
error: unable to unlink old 'appsettings.json': Invalid argument
# ... and many more similar errors for various .dll files
This typically occurs when Git cannot remove or modify certain files, often due to them being in use by running processes or locked by the operating system.
Quick Solution
Here’s the simple three-step solution that resolved the issue:
- Move all contents (except the
.gitfolder) to an archive folder outside the repository root - Ensure only the
.gitfolder remains in the repository directory - Run
git stash push -u(orgit stashwith appropriate flags for untracked files)
Why This Works
The solution works because:
- Moving files outside the repository temporarily releases any file locks
- Keeping only the
.gitfolder ensures Git can properly manage its internal state - The
-uflag in the stash command ensures untracked files are included in the stash
Prevention Tips
To avoid this issue in the future:
- Close any running instances of your application
- Close IDEs or editors that might be locking the files
- Ensure antivirus software isn’t interfering with file operations
- Consider using
.gitignorefor build outputs and dependencies
Technical Details
The error commonly occurs with:
- Build output files (
.dll,.exe,.pdb) - Configuration files (
appsettings.json) - Referenced assemblies in the
refs/directory
This is particularly common in .NET Core applications where the build process generates multiple interdependent files.
by
Tags:
Leave a Reply