I don't understand what happened. I did
git add .
git commit
and suddenly I see a list of a bunch of desktop.ini files committed.
(I don't understand why previous commits did not get any of them, and what might have suddenly changed, but that's an aside)
So, I undid the commit
git reset --soft HEAD~1
Added a line to .gitignore:
./**/desktop.ini
And did another
git add .
git commit -m "test"
Still adding a bunch of desktop.ini. What am I doing wrong?
The Desktop displayed by Windows when you start your computer or device is a combination of your user's Desktop and the Public Desktop folder. You see two desktop. ini files because two folders combine to create your Desktop, each with its own desktop. ini: one for your user account and one for the Public Desktop.
The Desktop. ini file is not visible by default as it's a protected operating system file. If it's suddenly appearing on your PC, you or another user have changed your folder settings to display hidden folders.
Some times, even if you haven't added some files to the repository, git seems to monitor them even after you add them to the . gitignore file. This is a caching issue that can occur and to fix it, you need to clear your cache.
ini keep appearing? The Desktop. ini file keeps appearing on your Windows 11/10 system mainly if the Hide protected operating system files option is unchecked in Folder Options. It is a system file that will be recreated automatically.
Just write this simpler thing into your .gitignore
:
desktop.ini
You could also do
**/desktop.ini
but it has the same effect. See man gitignore
for details.
Then do something like this to get files out of the index:
git reset --soft
git add .
Your git reset --soft
did not reset the index: you canceled the commit, but the files are still in the index (i.e. "added"). So, when you committed again, you got the same commit with the same files.
You wanted to to git reset --mixed
(or omit --mixed
which is the default anyway) to reset the index (but not the working tree).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With