0

On my production server I have a deploy script to do a git pull origin master among other deployment tasks when it receives a github webhook saying there's a new push to master. It works, but it keeps the full history which is just a waste of drive space.

Is there a way to truncate the history to keep only the current version?

  • That is how git works. You ask for that branch and that's what you get. Is git really what you want? Maybe you should build a tarball instead and deploy that. – Michael Hampton Mar 12 '21 at 21:04
  • I understand, that's why I am asking how to truncate the history because for deployment purposes I do not need historical versions. You say just build a tarball but that still would come from git. –  Mar 12 '21 at 22:46
  • If it's on github then you could just let it make the tarball for you dynamically, as it does. – Michael Hampton Mar 12 '21 at 23:03
  • Except its a private repository so its not publicly accessible. I got a deploy key to pull over ssh, there is no equivalent to download a tarball over ssh using a deploy key afaik. –  Mar 12 '21 at 23:20
  • Hmm. Well, the unanswered question is still: Is your project even large enough that this is an issue? If you aren't trying to solve a problem that doesn't exist and you really do have a disk space problem, then you should go back to building the tarball elsewhere and having production pick up the tarball. – Michael Hampton Mar 12 '21 at 23:43
  • After a couple of days searching around I think I found what I need! Would not adding `--depth=1` do exactly what I want? Or do I misunderstand what that does? –  Mar 14 '21 at 21:13
  • That might work, but you should try it somewhere else before production. – Michael Hampton Mar 14 '21 at 21:15
  • I don't get it. If I add depth=1 to git clone it clones only the current version. but adding it to to the pull command does nothing. It still sees the original cloned version as the only version. If I clone with a depth of 1 but do a regular clone it its basically as if I am starting my history from where I cloned, but each pull adds to the history from there. I don't get it. Do I have to nuke the directory and start over with a fresh clone each time? Or could I just after pulling, remove the older hisotry, so for a small period I have 2 versions but no more? –  Mar 14 '21 at 22:28
  • I looked back on what you said about getting a tarball. After some searching it seems you can do that with a Personal Access Token on a private repository, see https://www.funkycloudmedina.com/2020/06/how-to-download-a-private-github-repository-zip-via-api/. I just tested this command `curl -H "Authorization: token " -L https://api.github.com/repos///tarball/master | tar -xz` and it works errr kindof, it ends up in a folder with an odd name, and I am not sure how to know what name to expect, it starts off with the org and repo name but ends with a hash maybe? –  Mar 14 '21 at 23:04
  • Looks like it's the org-repo-commit. That should be easy enough to deal with. – Michael Hampton Mar 14 '21 at 23:08

0 Answers0