Since there is no copy-paste example for creating a commit without using files on disk with libgit2 as far as I can tell I thought I should add one.
Don't forget that libgit2 is in full development at this time (March 2013) so have a look at official documentation and source code, as new features are added daily:
- libgit2 API
- headers are very well commented - here's an example
- extensive tests may be a source of inspiration
- there are some official examples, general.c is a good place to start
- inspiration may be found in LibGit2Sharp - here are some tests
The repository comes from
git_repository_init()
orgit_repository_open()
. The signature comes fromgit_signature_now()
orgit_signature_new()
.The function updates the HEAD for current branch.
If you do a
git status
after the function executes you will notice that the filename-of-the-file.txt
appears as being deleted. That is because the function does not create an actual file, only an entry in the git database.Also, note the last arguments of
git_commit_create()
. 0 and NULL means that this is the first (root) commit. For all other there should be at least a parent commit specified, maybe obtained usinggit_commit_lookup()
.I'm just learning these things. Please improve this answer if you know better.