Should website image files be included in GIT repo

2019-06-21 08:10发布

问题:

I have a website file/folder structure template to start using with git. It contains an empty .gitignore file inside the images folder, which leads me to my two part question:

1.) Will this empty .gitignore file ignore all the images located inside the images folder, or was it placed there to allow the empty folder to be added to the repository before any images were placed inside?

2.) Should website images be included in a git repository? To me, image files are edited and altered just the same as other files, and it would be beneficial to keep track of said changes over time.

What is considered best practice? What do you do, and why?

回答1:

  1. In your case, the .gitignore allow git to "see" the directory. It could be any other file. Git doesn't store empty folder. You have to put this line into your .gitignore to tell to ignore all other files: !.gitignore
  2. There is no absolute response but I advise you to keep your images in the repository with the other files. Consider your git repository as your versionned website, images included. It will ease you if you want to automate your deployments. It will keep your website history consistent too. GIT handles images like any other files.


回答2:

Check out 'setup with binaries' and specifically 'git media' and 'git annex'. But, it is perfectly fine to use GIT directly with image files with one caveat - if you try 'git rebase' there can be a crash when comparing two large images.