0

I want to use Git to essentially just backup specific file types like .png and .jpg. So that there's never more than one copy of those files in my repo.

I imagine I could remove the files from Git and then recommit them every time, but I'd like to do that only when there's actually been a change in the file to avoid unecesssary copy time.

To describe my use-case: I use git with Xcode just to view changes of source files. I push to a cloud synced folder to have a backup of my project. I want to backup my resources like images in the same commit action, but not keep multiple copies/changes of them in my repo.

James
  • 359
  • 2
  • 12
  • 1
    What is the problem with just using git as intended? It t do anything unless the file changes... – Mad Physicist Jul 17 '19 at 20:46
  • 1
    I'm not sure I understand the question. Can you give an example of your use-case and what git currently does vs what you want it to do? – MyStackRunnethOver Jul 17 '19 at 20:51
  • @MadPhysicist I want to do this for large files and not bloat the repo size – James Jul 17 '19 at 20:51
  • @James. If the file is not in the repo, how is git going to A) be a backup, and B) know when it's changed? I still don't understand what your question is. – Mad Physicist Jul 17 '19 at 20:52
  • Are you asking how to remove the blobs representing previous versions beyond the immediate last change? – Mad Physicist Jul 17 '19 at 20:53
  • @James it is generally recommended that you not use Git with large, non-text files in part because of concerns over repo size. I'm also a bit confused how you're using this as a backup. Git is a version control tool, not a backup tool. – PhiloEpisteme Jul 17 '19 at 20:54
  • @MyStackRunnethOver I described my use-case. Hopefully that's more clear – James Jul 17 '19 at 20:56
  • @PhiloEpisteme. Git is a great backup tool, especially if you have a physically remote repo and text data. – Mad Physicist Jul 17 '19 at 20:58
  • @MadPhysicist I do want the file in my repo and I do want to know when a change is made. Once I commit the new change I don't want to keep its previous commit. I'm not familiar with blobs, so perhaps I'm asking that. – James Jul 17 '19 at 21:01
  • @PhiloEpisteme I edited my question and described my use-case. I want to commit large files without versioning them specifically to reduce repo size. – James Jul 17 '19 at 21:07
  • @James. Blobs are the compressed bits that git keeps the actual content in. For binary files, that's just the file itself, so yes, you're asking how to remove all previous blobs for a given file. – Mad Physicist Jul 17 '19 at 21:07
  • This doesn't seem to be a programming question. "*I do not want version my large files.*" OK, but then why insist on using a version control system? – melpomene Jul 17 '19 at 21:07
  • @James. I think you are looking for a pre-commit or possibly post-commit hook here. You could filter your branch to remove all previous references to the file, or to point them all to the most recent version. I have never done something like that and don't want to do the research now, but conceptually, that should get you started. – Mad Physicist Jul 17 '19 at 21:09
  • @MadPhysicist Ok. I suppose I could commit and then remove the older blobs, but it would be nice if that would happen automatically with the commit. – James Jul 17 '19 at 21:10
  • @melpomene. Hopefully my suggestion brings it back to the realm of programming. I am still not sure that it is on topic here, but the idea is at least interesting. – Mad Physicist Jul 17 '19 at 21:10
  • @MadPhysicist Thanks I'll look into hooks – James Jul 17 '19 at 21:11
  • @James. A post-commit hook would do exactly that: make it automatic whenever you complete a commit. Post-commit is probably the better option because it would allow you to point everything to the updated blob, instead of invalidating old versions of the code that reference the image. – Mad Physicist Jul 17 '19 at 21:12
  • @melpomene I do want to version control some but not all of my files – James Jul 17 '19 at 21:12
  • @James. Probably more important than hooks is filtering. Either way, you'll have a massive scripting journey ahead. If you manage to do this, publish it on Git or similarHub, and post the link here. I'd love to see what you come up with. – Mad Physicist Jul 17 '19 at 21:13
  • @MadPhysicist Oh great lol! Here I was hoping for a one line trick in like an attributes file – James Jul 17 '19 at 21:15
  • @James. It will be for everyone else once you finish it :) – Mad Physicist Jul 17 '19 at 21:16
  • @James. Is this an answer to your question: https://stackoverflow.com/q/6358476/2988730? – Mad Physicist Jul 17 '19 at 21:18

1 Answers1

1

Large files and binaries should NOT be committed.

Git should be used for,

...easily storing changed to text files wherever you are, and then easily copying them up to a server or servers or sharing them with your friends locally. “Text files” is the key here. It easily lets you see textual changes. But this function is useless for binary data. Data about changes in binary files just makes the commits impossible to read.

And also,

It’s important to never commit binary files because once you’ve commit them they are in the repository history and are very annoying to remove. You can delete the files from the current version of the project - but they’ll remain in the repository history, meaning that the overall repository size will still be large.

Instead, you can use Git Large File Storage (LFS),

Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or GitHub Enterprise.

oxr463
  • 1,573
  • 3
  • 14
  • 34