2

I wish to make a change in one file in my git repo, via browser.

I naturally headed to the Github API to see what I can do. The Create a commit endpoint requires the hash of a tree object. Is there a way to generate this tree hash inside a browser?

My repo is around ~100Mb, so cloning it inside the browser is not doable. Is there a way to clone a subfolder (sparse checkout) and then calculate the new tree hash, all in browser (with a git-inside-browser tool like isomorphic-git)?

Github has an UI for manually editing the files in their webapp. I am trying to recreate the same thing in my own webapp.

jeanpaul62
  • 9,451
  • 13
  • 54
  • 94
  • This is just not how GIT works. GIT is based on repositories, you never change files your change the repo (the file is just an unpacked representation of something in the repo). So you do need to clone it. The Git hub web edit will have a copy of the repo somewhere on the server. You could do the same thing, but you will need a local copy somehwhere – Liam Jul 31 '18 at 15:40
  • Possible duplicate of [How to update a file in remote repo, without cloning that repo first?](https://stackoverflow.com/questions/16077691/how-to-update-a-file-in-remote-repo-without-cloning-that-repo-first) – Liam Jul 31 '18 at 15:42

1 Answers1

1

There is no need to clone the repository. The Git Database API documentation gives the steps necessary to make a new commit:

  • Get the current commit object
  • Retrieve the tree it points to
  • Retrieve the content of the blob object that tree has for that particular file path
  • Change the content somehow and post a new blob object with that new content, getting a blob SHA back
  • Post a new tree object with that file path pointer replaced with your new blob SHA getting a tree SHA back
  • Create a new commit object with the current commit SHA as the parent and the new tree SHA, getting a commit SHA back
  • Update the reference of your branch to point to the new commit SHA
Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240