Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble unstaging, deleting even untracking a file

I have newly cloned a private repository noticing that it has already a staged file that is on status deleted:

issuing git status gives me this:

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        deleted:    rootfolder/site/templates/article.php

I wanted to make this working directory clean, the trouble comes when I unstage, untrack or even delete gives me error something like below:

git -c diff.mnemonicprefix=false -c core.quotepath=false reset -q HEAD -- "rootfolder/site/templates/article.php "

error: Invalid path 'rootfolder/site/templates/article.php ' fatal: make_cache_entry failed for path 'rootfolder/site/templates/article.php '

Any advise on how can i resolve this, Thanks in advance.

like image 490
EugeneSantos Avatar asked Nov 09 '22 21:11

EugeneSantos


1 Answers

For me it was a Windows/Linux thing. My travis build (on Linux vm) ran some tests in my code, creating files in C:/SomeFolder/someTestResult.file. It then proceeded to commit these changes and push to github in the C:/ folder.

The trouble came when I tried to git clone on my windows machine:

$ git clone [email protected]:awesome/somegitrepo.git
Cloning into 'somegitrepo'...
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 940 (delta 5), reused 13 (delta 5), pack-reused 926
Receiving objects: 100% (940/940), 500.23 KiB | 364.00 KiB/s, done.
Resolving deltas: 100% (373/373), done.
error: Invalid path 'C:/SomeFolder/someTestResult.file'

Clearly something went wrong because of the C:/ folder. GIT on windows saw the C:/ not as a local directory, but as the root directory, so the Linux local someTestResult.file was not there on the Windows git repo. I guess it then assumed it was deleted and staged the deletion even before I made any changes whatsoever.


My solution was to open up a Linux terminal (WSL) and delete the file from repo and push in order to clean the remote repository.

So basically (in the WSL):

$ git clone [email protected]:awesome/somegitrepo.git
$ rm -rf C:/
$ git add .
$ git commit -m 'Removed residue test files'
$ git push

I also changed my tests to not produce strange directories and put the generated test files in the .gitignore anyway.

like image 120
Shell Code Avatar answered Nov 15 '22 06:11

Shell Code