Help, I staged a file by accident
Take a file out of the next commit without touching what is in it.
git status Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: secrets.txt
The fix
git restore --staged secrets.txtUnstages the file. Your changes to it stay exactly as they are.
secrets.txt is an example. Replace it with your own.
Why this works
Staging only puts a file on the list for the next commit. restore --staged takes it off that list again and leaves your edits alone. In a brand-new repository without any commits, use git rm --cached secrets.txt instead, because there is no last commit to restore from yet.