I want to see the history of my Overleaf v2 document in my favourite diff viewer, so I want to export it as a git repository. Unfortunately, Overleaf v2 has no git support yet (at least not for the general public).
How do I export my document's history as a git repository?
You'll need
curl
,unzip
and a bash shell.Login to Overleaf in your browser and open your document: https://www.overleaf.com/project/YOUR-PROJECT-ID
Click "History" in the top right corner and select the most recent change.
Open the dev tools of your browser (Ctrl+Shift+K in Firefox, F12 in Chrome)
Click on the "Download project at this version" link. Your browser opens https://www.overleaf.com/project/YOUR-PROJECT-ID/version/MAX/zip, where MAX is the incremental ID of your most recent revision (probably a fairly high integer, it was 413 for me, and that was a project I just started working on). You can cancel the download, we don't actually care about it.
Using the dev tools, look at the cookies your browser sent. There should be five of them:
_ga
,_gid
,overleaf_session
,SERVERID
, andsixpack-clientId
.Open a shell and do
mkdir overleaf-git-export
andcd overleaf-git-export
Bulk download all ZIP snapshots of your project with CURL. You have to set the cookies you just inspected in the browser (obviously I shortened mine for this example) and set the MAX variable you found in the URL:
curl --cookie "_ga=GA1...;_gid=GA1...;overleaf_session=meRG...;SERVERID=sl-l...;sixpack-clientId=5c17..." https://www.overleaf.com/project/YOUR-PROJECT-ID/version/[1-MAX]/zip -o zip#1.zip
This can take a while (my 413 revisions needed 20min).Initialise our working folder for the script we'll be using soon:
mkdir gitsave
,mkdir repo
,cd repo
,git init
,cd ..
Then use this script (note that you'll have to adjust the MAX variable and the paths to your
overleaf-git-export
folder). It incrementally replaces the content of the repo with the content of the revision and commits it, fully wiping the repo in between but of course preserving the.git
folder which contains the git history we want. This was surprisingly quick for me (a few minutes for all 413).Hope this helps someone until proper git support becomes available for Overleaf v2.
Note that the individual commits will be very tiny. If you want bigger chunks of changes, you could scrape the "History" section on the Overleaf website for the revision IDs that matter.
[EDIT 2021]
The cookies are different. There is another strategy for creating the right
curl
invocation. Steps are for Firefox, but should apply similarly to other browsers.Network
tabNetwork
tab. It should be aGET
for azip
.The clipboard should contain something like
with many other
-H
arguments. Only the part of the header corresponding to the cookie is needed, and the rest can be removed.