Solved, as explained in a comment under the accepted answer.
I have been using Git since years and I am really surprised that I there is one specific file that I can't add to the staging area in one of my repos! I don't want to delete and recreate the repo but to understand what is going on and fix it. Also, now I am worried that maybe there are other files that are not being added to the repo (or in other repos).
I have one repo in which I have just committed and pushed successfully a bunch of files, and then I have realized that one of them, init.el
, didn't get uploaded.
This is what I have:
- Running
git add init.el
does not produce any output - The file (or a pattern matching it) is not specified in any
.gitignore
file (in the current folder, in a child folder, or in one of the parent directories until the root). - There is not parent Git repository that I have accidentally created and that is messing with that file
- The file (or a patter matching it) is not listed in
.git/info/exclude
- The file (or a pattern matching it) does not appear when I run
git ls-files --others -i --exclude-standard
I have then tried removing the file rm init.el
, which correctly leads to
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: .gitignore
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: init.el
Then, I have tried doing git rm init.el
, which again correctly led to
rm 'init.el'
But putting back the file and then adding the file with git add init.el
shows no output, and the file is still missing from the staging area (I have checked this with git status
, git diff --cached
and by committing and pushing (see next line)).
Trying to commit, push and double check what is going on in Github confirms that the file has not been added.
You never stops learning, is there anything standard that I am unaware of that may be triggering this behavior, or is this an error and so is there a way I can repair the repo?
EDIT, to answer one comment
pwd
gives/Users/my_user/.my_spacemacs.d
cat .gitignore
gives
.DS_Store
spacemacs_d_backup2020/
find . -name '.gitignore'
gives
./spacemacs_d_backup2020/.gitignore
./.gitignore
- finally,
cat ./spacemacs_d_backup2020/.gitignore
gives
.DS_Store