You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 3, 2023. It is now read-only.
Gregor Dschung edited this page Apr 9, 2015
·
5 revisions
The following examples assume you already have a repository in place to work with. If not, see git-init.
Make a commit to a non-bare repository
If you want to commit to a repository that is checked out to the file system, you can update the file on the file system and use the repository's Commit method.
using(varrepo=newRepository("path/to/your/repo")){// Write content to file systemvarcontent="Commit this!";File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory,"fileToCommit.txt"),content);// Stage the filerepo.Stage("fileToCommit.txt");// Create the committer's signature and commitSignatureauthor=newSignature("James","@jugglingnutcase",DateTime.Now);Signaturecommitter=author;// Commit to the repositoryCommitcommit=repo.Commit("Here's a commit i made!",author,committer);}
Make a commit to a bare repository
using(Repositoryrepo=newRepository("path-to-bare-repo")){stringcontent="Hello commit!";// Create a blob from the content streambyte[]contentBytes=System.Text.Encoding.UTF8.GetBytes(content);MemoryStreamms=newMemoryStream(contentBytes);BlobnewBlob=repo.ObjectDatabase.CreateBlob(ms);// Put the blob in a treeTreeDefinitiontd=newTreeDefinition();td.Add("filePath.txt",newBlob,Mode.NonExecutableFile);Treetree=repo.ObjectDatabase.CreateTree(td);// Committer and authorSignaturecommitter=newSignature("James","@jugglingnutcase",DateTime.Now);Signatureauthor=committer;// Create binary stream from the textCommitcommit=repo.ObjectDatabase.CreateCommit("i'm a commit message :)",author,committer,tree,repo.Commits);// Update the HEAD reference to point to the latest commitrepo.Refs.UpdateTarget(repo.Refs.Head,commit.Id);}