10

I have a development server and a couple of production ones. I do commits from the dev to a remote repository and have git push production setup, that issues a pull from the production servers. I needed to remove a couple of directories with static files from being tracked so I did this

Remove an Existing File from a Git Repo (summary: did git rm --cached myfolders, and after that added to .gitignore the folders)

I have not yet committed the changes. The files show as deleted when doing git status

#       deleted:    file1.jpg
#       deleted:    file2.jpg
#       deleted:    file3.jpg
#       deleted:    file4.jpg
#       deleted:    file5.jpg

My concern is: will the 'deleted' files be removed from production servers (from disk) when git pull is being performed? I just want them untracked, but not deleted from disk.

Thanks

Community
  • 1
  • 1
Mecca
  • 641
  • 1
  • 7
  • 17
  • 2
    I can't help thinking that managing a deployment to production in this way is not a good idea. – Brian Agnew Aug 17 '11 at 19:55
  • I agree with you. Don't know if you would consider it better that the pull is not really automatic, I do "git push production" from dev. Edited the question. I personally prefer a rsync script to do all that. – Mecca Aug 17 '11 at 20:24

3 Answers3

13

Yes, if you pull a commit that includes deletions, the files will be deleted. You'll need to restore the files manually afterwards.

Amber
  • 477,764
  • 81
  • 611
  • 541
5

Yes, the files will be deleted if you do a git pull. Git couldn't do anything else - suppose some code in the repository depended on the existence or non-existence of some file. Removing a file might have a significant resulting behaviour, so Git must remove the file when pulling.

Greg Hewgill
  • 890,778
  • 177
  • 1,125
  • 1,260
2

As the others answered, you need to restore the deleted files manually. You can do that with

git checkout sha1 -- file1.jpg file2.jpg

where sha1 is the commit beofre the merge. There are multiple ways to get that one, like with HEAD~1 or the easiest copy from the output from the pull. There is something like

Updating bea26f6..d5a6bc6

where the first commit was the one you had localy before.

inetphantom
  • 2,267
  • 1
  • 35
  • 60