Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull - deleted files

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

like image 978
Mecca Avatar asked Aug 17 '11 19:08

Mecca


People also ask

Does git pull files to delete?

If you have committed the deletion and pushed it to GitHub, it is possible to recover a deleted file using the GitHub Web UI. GitHub lets you browse the commit history and explore the project at any point in history, which then allows you to view and download any file.

How do you undo a delete in git?

Even better, in cases like committing a file deletion and then wanting to revert it, Tower's awesome undo feature lets you get the file back by simply pressing CMD-Z!

Is there a way to restore deleted files?

Right-click the file or folder, and then select Restore previous versions. You'll see a list of available previous versions of the file or folder. The list will include files saved on a backup (if you're using Windows Backup to back up your files) as well as restore points, if both types are available.

How do I recover files from a git push?

You can just use git reset 'commit id contains your deleted file' then merge and push it again. Show activity on this post. You should use git reset HEAD~ and then use git checkout -- <filename> to restore deleted files. You are assuming the deletion was made in previous commit, what if it was deleted long time ago.


2 Answers

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.

like image 139
inetphantom Avatar answered Nov 10 '22 01:11

inetphantom


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

like image 45
Amber Avatar answered Nov 10 '22 01:11

Amber