I don't know the main reason but once in a while git
completely removes the content in a buffer/file that I am working on if the commit is not completed successfully.
After file's content is cleaned, file's undo-tree is not able to fetch the latest changes using emacs
as well, instead its tree is completely empty. I am not able to find the latest changes I have and they do not show up in stash
.
In the background: zsh's git auto-fetch is running, I am not sure would that have any affect.
=> Is there anyway to prevent for git
to completely delete the content of a file?
The file (scripts/lib.py
) is not located in the .gitignore
or ~/.gitignore_global
.
git check-ignore -v -- scripts/lib.py
returns empty
Please note that the file remains as it is with 0 bytes
❯ ls -lA -tr -h | grep lib.py
-rw-r--r-- 1 alper alper 0 2021-01-04 22:09 lib.py
Check if your file would be deleted by a git clean -ndx
(the -n
is important: it will preview what would be deleted, instead of actually deleting any file)
Check also if that same file is ignored:
git check-ignore -v -- the/temp/file
(It could be ignored by a global core.exclude
file)
In both cases, that would point to a recurrent git clean
as a possible cause for the file deletion.
Since the check-ignore did not return anything, that points to a root cause external to Git, more linked to Emacs, as the OP points out in the comments.