If I set up a post-recieve hook in git like
#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f
Will that delete files that are on the server but not on my local git repo?
If it will, is there any way to stop that?
Git checkout will not remove files added since a previous commit.
git checkout does not affect untracked files. Git only manages tracked files, and it works fairly hard to avoid letting you lose data (which is critical).
The git checkout command can be used in a commit, or file level scope. A file level checkout will change the file's contents to those of the specific commit.
Yes, it is safe.
It depends if the files will be deleted depending if they already existed in the repository prior to the checkout.
If the files that are on the server (/var/www/www.example.org) are tracked in the repo on the server but the new checkout includes a change that removed them then they will be removed on the server side.
If the files that are on the server are NOT tracked in the repo on the server then they will stay. Since Git doesn't know about them Git won't remove them.
To tell if they are tracked on the server you can do git status <file in question>
. If it says:
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# <file in question>
Then you know that a checkout would not remove .
Just take note if later exists in a new checkout than the next checkout which removes would remove it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With