3

I have some .swp files that were created by my editor and committed previously by accident. Now I want to merge into master, but need to get rid of these files. I tried to delete them from my working copy, and then commit. Now the files are deleted locally but still present in the commit on github. I have tried git rm path_to_files, but this returns fatal: pathspec 'path_to_files' did not match any files, which seems to confirm that they are totally gone from my local copy. How can I remove them entirely? Thanks.

Canaryyellow
  • 157
  • 6
  • Maybe [this solution](http://stackoverflow.com/questions/12179611/proper-way-to-remove-unwanted-files-with-git-filter-branch-without-git-rm-failin) helps. – ckruczek Oct 08 '15 at 04:51

2 Answers2

1

Since your files are deleted locally from the file system, you should be able to do:

git add . -A
git commit -m 'Deleted files'

Or just:

git commit -m 'Deleted files' .

(notice the point at the end, that will add the deleted files)

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • So simple, thanks. It's weird, I originally deleted the files and pushed to origin at work, then when I got home I pulled and am now making this delete commit. How did my home computer get the list of files that had been deleted, if they were not already synced with origin. If they were synced with origin, why was this necessary? – Canaryyellow Oct 08 '15 at 04:57
  • @Canaryyellow `git` says you deleted files on your home computer (where you just run these commands). Maybe when you go to work you will see that you didn't add the deleted files (using `-A`). `:-)` When deleting files, you have to use `git add . -A` (`git add .` is not enough). Probably you didn't push the deleted files from work. Or if you're using another syncing app (e.g. Dropbox), that may explain why they got deleted on this machine. – Ionică Bizău Oct 08 '15 at 05:30
0

If you have deleted the file locally just commit the operation

git commit -a -m "Committing deletion of files"
git push
Anurag Verma
  • 485
  • 2
  • 12