Reputation: 57
I am using git / github for a project. It is mostly to host code sources, but it also contains some large images. I will have to update the large images from time to time, but I don't want to keep the history of it, I only want the latest version in my git / github.
Is there a way to say to git: "keep this file, but don't keep any history of it"? If not, how can I manually and safely delete the history of my file right after commit / push?
Thank you for your help!
Upvotes: 2
Views: 115
Reputation: 1325
Develop using one branch that always has one last commit that adds large files.
All commits except this one should NOT add any of that large files.
To make changes to source files you'll need to commit on top of that large one, and then use git rebase
(example that assumes that you are working in master branch: git checkout -b src HEAD~1 && git cherry-pick master && git rebase src master && git branch -d src
) command to pop large commit on top of all source commits.
To update the set of large files you'll need to make that large commit to be the last one and amend it instead of creating new one.
In this case you'll be unable to use default git push
behavior that makes only fast-forward refs updates and you'll have to make forced updates like git push <repository> +master:master
(note the + sign).
UPD: There is similar question with similar answer Managing large binary files with git.
I noticed that after I wrote my answer.
Create separate repository for large files and use it in main repository as git submodule.
To make modifications to source files you can simply make regular commit in main repo.
And when you'll need to update the set of large files in submodule repo you'll have to amend the only commit there instead of making new one.
Upvotes: 1