I have a github repo that I somehow horked up from Mac that I can no longer switch branches in.
My .NET 6.0 ASP.NET web site project uses NLog, which is a logging package configured by nlog.config XML file:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Info"
internalLogFile="c:\temp\internal-nlog-AspNetCore.txt">
The internalLogFile property where NLogs internal logging goes.
On Mac, the repo is in /Users/dodievich/mycompany/myprojectname directory.
Few months ago I loaded and ran this project from Mac, which caused NLog to create /Users/dodievich/mycompany/myprojectname/c:\temp\internal-nlog-AspNetCore.txt file where c:\temp\internal-nlog-AspNetCore.txt is the full file name, not the file path (backslashes are part of filename on the Mac):
> ls *og*
-rw-r--r-- 1 dodievich staff 3889 Jul 12 18:29 NLog.config
-rw-r--r-- 1 dodievich staff 1611 Jul 12 18:29 c:\temp\internal-nlog-AspNetCore.txt
For bonus unhappy path stuff, pwsh on Mac goes a bit nuts (but that's just to indicate that mixing windows and mac paths between OSs is evil):
PS /Users/dodievich/mycompany/myprojectname> Get-ChildItem *log*
Directory: /Users/dodievich/mycompany/myprojectname
UnixMode User Group LastWriteTime Size Name
-------- ---- ----- ------------- ---- ----
drwxr-xr-x dodievich staff 7/12/2022 18:22 96 logs
Get-ChildItem: Could not find item /Users/dodievich/mycompany/myprojectname/c:/temp/internal-nlog-AspNetCore.txt.
-rw-r--r-- dodievich staff 7/12/2022 18:29 3889 NLog.config
When that happened, I added .DS_Store and c:\temp\internal-nlog-AspNetCore.txt files to .gitignore to ignore. I didn't think twice to check that in from my Mac:
> git diff <commit n> <commit n+1>
diff --git a/.gitignore b/.gitignore
index e06b49c..0bd5af8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -332,3 +332,5 @@ ASALocalRun/
# Local History for Visual Studio
.localhistory/
+c:\temp\internal-nlog-AspNetCore.txt
+.DS_Store
Meanwhile, on Windows VM, the repo is in C:\mycompanyname\myprojectname directory.
I usually work in main branch. Recently, another developer created anotherbranch branch which I am unable to switch to on my Windows VM. I receive this error:
> git checkout -q --track origin/anotherbranch
error: The following untracked working tree files would be overwritten by checkout:
c:\temp\internal-nlog-AspNetCore.txt
Please move or remove them before you switch branches.
Aborting
If I delete c:\temp\internal-nlog-AspNetCore.txt, the error changes to:
> git checkout -q --track origin/anotherbranch
error: invalid path 'c:\temp\internal-nlog-AspNetCore.txt'
As you can see from the path the c:\temp\internal-nlog-AspNetCore.txt is outside of where the repo is at in C:\mycompanyname\myprojectname.
I'd really like to be able to switch to another branch. I think my adding this file to .gitignore made it track somehow? No combination of git clean, git reset, git rm or removal of this file from .gitignore seems to be able to make this error go away.
What can I do?