0

I added a folder to .gitignore and some files went missing in the system, they were PDF files and since I understand binary files should not be in git I added the folder containing those files in .gitignore. I though it would not affect the existing files in the systems but some of them are not in the server anymore.

Could it be due to me adding .gitignore? Or should I discard this possibility?

  • Already tracked files will not be auto deleted just by changing the .gitignore file. You have to delete/ remove them (cached) manually: https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore – Alex Jun 17 '21 at 12:40
  • So, its not possible the files were deleted just because they were added to .gitignore? – Enrique Uzcategui Jun 17 '21 at 12:56
  • "missing in the system" : can you explain what system that is, and what actions you did on it ? – LeGEC Jun 17 '21 at 13:30
  • for example : if you removed those files from versioning on your workstation, pushed to a central remote, and then went to a server and ran `git pull`, then on the server, these files will be removed (they are still somewhere in git, though) – LeGEC Jun 17 '21 at 13:30
  • Note that existing commits *cannot be changed*, not even by Git itself. So if you have existing commits that contain the files, they still contain the files, and will forever (or until you discard those *commits*, perhaps by replacing them with new-and-improved commits). In your case it sounds like you don't want to lose the files, so you shouldn't be adding them to `.gitignore` anyway. – torek Jun 17 '21 at 15:47
  • Each commit is an archive of every file. Past commits are past archives. New commits are new archives. That's really all there is to them—well, that plus a bit of metadata, that makes them work as history. An archive must be *extracted* to use it. – torek Jun 17 '21 at 15:48
  • I did not remove the files from the systems (not in my local machine nor in the server), I only added them to .gitignored and the dissapeared, I just want to ensure it was not because of that – Enrique Uzcategui Jun 18 '21 at 14:15
  • Luckily they were in previous commits as you all said and I could restore them, but I am still worried those files get lost in future commits. Those are files that are being uploaded by the users so they are important. – Enrique Uzcategui Jun 18 '21 at 14:17

1 Answers1

1

No, adding files to .gitignore merely tells git that the files shouldn't be added to the system using git add for example (without -f at least) and git status will not show you that they are untracked.

However, because they're untracked you may lose status about them and may forget that they're important. Thus, if you delete your cloned copy of a repository that has the PDFs in them, then you've just deleted them yourself and have forgotten that they weren't part of the checked in files. Thus, you and other users that clone the repository won't get access to them.

If you're interested in storing large files in git, you might look at git annex and git lfs, which offers ways to store and share large files.

Finally, my general thought on PDFs and similar large files: it's best if your repository can self-generate them during a build or similar process. If not, then you do need to track them in a versioning system somehow to ensure they're not lost (hence: git annex or git lfs).

Wes Hardaker
  • 21,735
  • 2
  • 38
  • 69
  • The files are uploaded by the users of the app so they are really important but I don't think its good practice to have them tracked by git isnt it? Thats why I .gitignored them (previous dev did not did that so thats why they were being track by git) – Enrique Uzcategui Jun 18 '21 at 14:19
  • It comes down to: how badly do you want to ensure you have them in the future? Will you be upset if you lose them, or are they temporary? Does everyone that clones the repository likely need them? ---- If you're upset when they're gone, then some sort of backup is critical. That could be in git or not. ---- if everyone needs them, then putting them in git with some sort of large file support seems like a potentially right choice. – Wes Hardaker Jun 18 '21 at 14:55
  • They are not temporary and not everyone who clones the repo would them, only users need them and they are a lot so thats another reason why I dont think it'd be good idea to have them in git. – Enrique Uzcategui Jun 20 '21 at 01:44