I also sometimes meet the situation:
$ git add .
$ git commit -m "<commit-comments>"
[main xxxxxxxx] <commit-comments>
99 files changed, 99999 insertions(+)
...
create mode 100644 <unexpected-file>
"Hey, wait ( ゚д゚)"
In such a case, git reset HEAD^ <unexpected-file>
is available.
$ git reset HEAD^ <unexpected-file>
[main xxxxxxxx] <commit-comments>
98 files changed, 98888 insertions(+)
...
$ # "create ... <unexpected-file>" is not printed
$ git commit --amend
$ # HEAD^ is changed
Happier, possibly🙂
Besides, when git push
has been already done, running git push --force|-f origin main
after the commit above updates the remote repository. It may affect others.