Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will a git checkout delete files that shouldn't be there?

Tags:

git

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?

like image 897
qwertymk Avatar asked Feb 10 '12 17:02

qwertymk


People also ask

Will git checkout delete files?

Git checkout will not remove files added since a previous commit.

Does git checkout delete untracked files?

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).

Does git checkout change files?

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.

Is git checkout safe?

Yes, it is safe.


1 Answers

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.

like image 163
James Avatar answered Oct 07 '22 23:10

James