Same files listed as both untracked and deleted

后端 未结 2 1528
逝去的感伤
逝去的感伤 2021-01-12 11:16

Running git status in a Git repository, I get:

Changes not staged for commit:
  (use \"git add/rm ...\" to update what will be commi         


        
2条回答
  •  春和景丽
    2021-01-12 11:41

    It was actually a very simple thing: the files had been committed with a space at the end of the filename. Apparently Windows cannot handle this, and automatically removes the space every time (after clone, after checkout, etc.).

    So Git shows the correct information, the file "path/to/file1.sql " has been deleted, and the file "path/to/file1.sql" is new (sorry this didn't show in the question, now that I now I corrected it to show the space in the sample Git output).

    I couldn't notice this at first, because I simply lsed the content of the directory /path/to/ on Linux after seeing that git status was fine there, and tried to debug everything in Windows (not possible, unless you somehow notice that space by selecting the right part of the Git output). While I was performing an additional check on the filenames (on Linux) thanks to Vampire's comment I obtained the strange result

    ls /path/to/file1.sql
    ls: file not found
    

    After pressing TAB and seeing "/path/to/file1.sql\ " I figured it out. I think the problem is quite trivial, but since it doesn't happen everyday that someone commits files with a space at the end of the name, I think it can take a while to figure out there is no real problem with Git.

    So I'm going to leave the question and the answer for now, if you disagree just downvote and I'll delete everything.

    Thanks to everyone who helped in the comments.

提交回复
热议问题