0

I am using git for version control and need to delete a file from the repo.

Earlier I had folder structure as follows in git repo

ProjectName/ src/ test/ java/ vanilla/ file1.java file2.java

Later on my local copy I added another folder endToendTests under vanilla and moved file1.java and file2.java to the new folder, committed and pushed. I thought the new folder and file move would reflect in repo too. But did not confirm in repo (I know my bad #cringing).

However after some more commits and pushes from me and my colleague I realized these files now show up in two places in repo under vanilla and under endToendTests folder. So I went looking for how to delete these files from under vanilla in git repo (they do not exist in two places on my local). My search lead me to these stack answers How to remove files from the GitHub repository? and How can I delete a file from git repo?

I tried below command

git rm ProjectName/src/test/java/vanilla/file1.java

and got below error

fatal: pathspec ProjectName/src/test/java/vanilla/file1.java did not match any files

Further search about this error led me try

git rm .ProjectName/src/test/java/vanilla/file1.java

This as well did not work.

Is the syntax to specify filepath incorrect? or is my command incorrect?

Any pointers on how I can get this file deleted from git repo is very much appreciated.

Thanks for your time!!

Community
  • 1
  • 1
puvi
  • 41
  • 1
  • 4
  • Git only reflects the actual actions you took. When you "moved" `file1.java` and `file2.java`, did you make copies or did you actually use the move command? When you committed, did you see anything in the stage which mentioned deleting these files? – Tim Biegeleisen Dec 24 '15 at 02:58

1 Answers1

0

To Delete a file from the GIT repo, use can use following steps -

1 - Clone your repository into your local machine. 
2 - Do checkout if you are working with any specific branch other then master.
3 - Delete your desired files. 
4 - Again commit and push your code with proper commit message. e.g. deleted abc.java file because.....

You will get your file deleted from your repository. Please let us know if you need help for the commands for above steps.

Abhishek
  • 3,304
  • 4
  • 30
  • 44