Search code examples
gitfortrabbit

Delete file from Git - confusion


I'm trying to learn to use Git, and I kind of get the basics of pulling and pushing etc, but I'm confused on deletions.

This is what I've done (with fortrabbit and laravel):

  • Created a Laravel Project
  • run git init . in the project folder
  • run git remote add origin ...
  • run git add -A
  • run git commit -am 'Initial'
  • run git push -u origin master

Now my local copy matches my remote copy.

I now want to delete a file, so I create a test file:

  • run touch testfile1.php

I add the file, commit it then push it. Now I have the test file locally and remotely.

The problem is deleting it. This question is in 2 parts:

Reading this SO question: How can I delete a file from git repo? it says I should do:

  • git rm testfile1.php
  • git commit -m 'deleted file'
  • git push origin master

However that only deletes the local copy. The remote copy is still there!

If I delete it from my local copy, how does it get deleted from the remote version too?

My second question is, if someone else has a copy, how do they know I've deleted the file? If they push their copy back to the remote one, won't it just re-add the deleted file?

Any help is appreciated.

EDIT

This is the output of the git rm command, and the remote version after the command:

enter image description here enter image description here

The first image is me typing the git rm testfile1.php file. It then outputs rm testfile1.php and returns to the prompt. When I SSH back into the remote version, the testfile`.php is still there :/

Another Edit

I've just been reading some help articles provided by Fortrabbit, primarily, this one: http://help.fortrabbit.com/git#toc-behind-the-scenes

It says the it overwrites, but doesn't delete.

Would this be the reason why git says it's up to date, but the file is still in the web root? If so, for what reason could there possibly be not to delete a file that I've asked to be deleted?!


Solution

  • This question is in fact specific to Fortrabbit : http://help.fortrabbit.com/git#toc-overwrite-but-not-delete

    Overwrite but not delete

    The old files will be overwritten with the ones that have been updated thru Git. However, Git deployment will not delete anything. So when you delete a file from your Git repo it will be still there in the webspace.

    This is the safe default to deal with "runtime contents". When you implement something like an image upload form, you will upload additional contents to your webspace. Those files are generated on the webspace directly. So they are not part of Git repo. But most likely you don't want these to be deleted whenever you push code changes.

    You can configure that behaviour with the fortrabbit.yml file:

    http://help.fortrabbit.com/deployment-file

    The contents of the file should be :

    version: 1 
    strategy: fullsync
    excludes:
         - app/storage/ 
         - uploads/
         - vendor/
    

    The fullsync means that the content of your webserver will be exactly the one as your local repository. The excludes key specifies which folders you would not autosync (you should put there all folders that could contain user data, like avatars, or things that are not in git but are required by your application like the vendor folder)