### Objective-C Coding Conventions Source: https://github.com/xiaobingtech/objective-git/blob/master/README.md A link to GitHub's Objective-C style guide, which should be followed for all contributions to the ObjectiveGit project. ```markdown [Objective-C coding conventions](https://github.com/github/objective-c-style-guide) ``` -------------------------------- ### Manage Git Branches with ObjectiveGit Source: https://context7.com/xiaobingtech/objective-git/llms.txt Demonstrates how to list, create, and get information about Git branches using ObjectiveGit. It covers retrieving the current branch, listing local and remote branches, creating new branches, and checking tracking information and commit differences. ```objc #import NSError *error = nil; GTRepository *repository = [GTRepository repositoryWithURL:repoURL error:&error]; // Get current branch GTBranch *currentBranch = [repository currentBranchWithError:&error]; NSLog(@"Current branch: %@", currentBranch.name); NSLog(@"Short name: %@", currentBranch.shortName); NSLog(@"Is HEAD: %@", currentBranch.HEAD ? @"YES" : @"NO"); // List all local branches NSArray *localBranches = [repository localBranchesWithError:&error]; for (GTBranch *branch in localBranches) { NSLog(@"Local branch: %@ (type: %@)", branch.name, branch.branchType == GTBranchTypeLocal ? @"local" : @"remote"); } // List remote branches NSArray *remoteBranches = [repository remoteBranchesWithError:&error]; for (GTBranch *branch in remoteBranches) { NSLog(@"Remote branch: %@ (remote: %@)", branch.name, branch.remoteName); } // Create a new branch from HEAD GTReference *headRef = [repository headReferenceWithError:&error]; GTBranch *newBranch = [repository createBranchNamed:@"feature/new-feature" fromOID:headRef.targetOID message:@"Created feature branch" error:&error]; if (newBranch) { NSLog(@"Created branch: %@", newBranch.name); } // Get tracking branch BOOL success; GTBranch *trackingBranch = [currentBranch trackingBranchWithError:&error success:&success]; if (success && trackingBranch) { NSLog(@"Tracking: %@", trackingBranch.name); // Calculate ahead/behind size_t ahead, behind; [currentBranch calculateAhead:&ahead behind:&behind relativeTo:trackingBranch error:&error]; NSLog(@"Branch is %zu commits ahead, %zu commits behind", ahead, behind); } ``` -------------------------------- ### Manage Remotes in Objective-Git Source: https://context7.com/xiaobingtech/objective-git/llms.txt Provides examples for managing remote Git repositories, including listing, creating, loading, updating URLs, adding refspecs, renaming, and deleting remotes. Essential for distributed Git workflows. Requires the ObjectiveGit framework. ```objc #import NSError *error = nil; GTRepository *repository = [GTRepository repositoryWithURL:repoURL error:&error]; // List remotes NSArray *remoteNames = [repository remoteNamesWithError:&error]; for (NSString *remoteName in remoteNames) { NSLog(@"Remote: %@", remoteName); } // Create a new remote GTRemote *remote = [GTRemote createRemoteWithName:@"upstream" URLString:@"https://github.com/user/repo.git" inRepository:repository error:&error]; if (remote) { NSLog(@"Created remote: %@", remote.name); } // Load existing remote GTRemote *origin = [GTRemote remoteWithName:@"origin" inRepository:repository error:&error]; if (!origin) { NSLog(@"Failed to load remote: %@", error); return; } NSLog(@"Remote URL: %@", origin.URLString); NSLog(@"Push URL: %@", origin.pushURLString); NSLog(@"Connected: %@", origin.connected ? @"YES" : @"NO"); // List fetch refspecs NSArray *fetchRefspecs = origin.fetchRefspecs; for (NSString *refspec in fetchRefspecs) { NSLog(@"Fetch refspec: %@", refspec); } // Update remote URL if ([origin updateURLString:@"https://github.com/newuser/repo.git" error:&error]) { NSLog(@"Remote URL updated"); } // Add fetch refspec if ([origin addFetchRefspec:@"+refs/heads/*:refs/remotes/origin/*" error:&error]) { NSLog(@"Fetch refspec added"); } // Rename remote if ([origin rename:@"origin-renamed" error:&error]) { NSLog(@"Remote renamed"); } // Delete remote if ([repository deleteRemoteNamed:@"old-remote" error:&error]) { NSLog(@"Remote deleted"); } ``` -------------------------------- ### Import ObjectiveGit Framework Source: https://github.com/xiaobingtech/objective-git/blob/master/README.md These are the standard Objective-C and modern Objective-C syntax for importing the ObjectiveGit framework into your project files. ```objectivec #import ``` ```objectivec @import ObjectiveGit; ``` -------------------------------- ### Initialize Git Repository with Objective-C Source: https://context7.com/xiaobingtech/objective-git/llms.txt Initializes a new Git repository at a specified file URL using Objective-C. Supports standard and bare repository initializations with optional configuration flags. ```objc #import NSError *error = nil; NSURL *repoURL = [NSURL fileURLWithPath:@"/path/to/new/repo"]; // Initialize a standard repository with working directory GTRepository *repository = [GTRepository initializeEmptyRepositoryAtFileURL:repoURL options:nil error:&error]; if (!repository) { NSLog(@"Failed to initialize repository: %@", error); return; } NSLog(@"Repository initialized at: %@", repository.gitDirectoryURL); NSLog(@"Is bare: %@", repository.bare ? @"YES" : @"NO"); // Initialize a bare repository NSURL *bareRepoURL = [NSURL fileURLWithFormatPath:@"/path/to/bare/repo.git"]; NSDictionary *bareOptions = @{ GTRepositoryInitOptionsFlags: @(GTRepositoryInitBare | GTRepositoryInitCreatingRepositoryDirectory) }; GTRepository *bareRepo = [GTRepository initializeEmptyRepositoryAtFileURL:bareRepoURL options:bareOptions error:&error]; if (bareRepo) { NSLog(@"Bare repository created: %@", bareRepo.gitDirectoryURL); } ``` -------------------------------- ### Open Existing Git Repository with Objective-C Source: https://context7.com/xiaobingtech/objective-git/llms.txt Opens an existing Git repository from a given file URL using Objective-C. Includes error handling and demonstrates how to access repository properties and state. ```objc #import NSError *error = nil; NSURL *repoURL = [NSURL fileURLWithPath:@"/path/to/existing/repo"]; GTRepository *repository = [GTRepository repositoryWithURL:repoURL error:&error]; if (!repository) { NSLog(@"Failed to open repository: %@", error.localizedDescription); return; } // Check repository properties NSLog(@"Working directory: %@", repository.fileURL); NSLog(@"Git directory: %@", repository.gitDirectoryURL); NSLog(@"Is bare: %@", repository.bare ? @"YES" : @"NO"); NSLog(@"Is empty: %@", repository.empty ? @"YES" : @"NO"); NSLog(@"HEAD detached: %@", repository.HEADDetached ? @"YES" : @"NO"); // Get repository state GTRepositoryStateType state; if ([repository calculateState:&state withError:&error]) { switch (state) { case GTRepositoryStateNone: NSLog(@"Repository state: Normal"); break; case GTRepositoryStateMerge: NSLog(@"Repository state: Merge in progress"); break; case GTRepositoryStateRebase: NSLog(@"Repository state: Rebase in progress"); break; default: NSLog(@"Repository state: %ld", (long)state); break; } } ``` -------------------------------- ### Create and Read Blobs in Objective-Git Source: https://context7.com/xiaobingtech/objective-git/llms.txt Demonstrates how to create blob objects from strings, data, and files, as well as how to read their content. It also shows how to look up existing blobs using their SHA or OID. Requires the ObjectiveGit framework. ```objc #import NSError *error = nil; GTRepository *repository = [GTRepository repositoryWithURL:repoURL error:&error]; // Create blob from string NSString *content = @"This is the file content\nLine 2\nLine 3"; GTBlob *blob = [GTBlob blobWithString:content inRepository:repository error:&error]; if (!blob) { NSLog(@"Failed to create blob: %@", error); return; } NSLog(@"Blob SHA: %@", blob.SHA); NSLog(@"Blob size: %lld bytes", blob.size); // Read blob content NSString *blobContent = blob.content; NSData *blobData = blob.data; NSLog(@"Blob content: %@", blobContent); // Create blob from data NSData *data = [@"Binary or text data" dataUsingEncoding:NSUTF8StringEncoding]; GTBlob *dataBlob = [GTBlob blobWithData:data inRepository:repository error:&error]; // Create blob from file NSURL *fileURL = [NSURL fileURLWithPath:@"/path/to/file.txt"]; GTBlob *fileBlob = [GTBlob blobWithFile:fileURL inRepository:repository error:&error]; if (fileBlob) { NSLog(@"Created blob from file: %@", fileBlob.SHA); } // Lookup existing blob GTCommit *commit = [repository lookUpObjectBySHA:@"abc123..." error:&error]; GTTree *tree = commit.tree; GTTreeEntry *entry = [tree entryWithName:@"README.md"]; GTBlob *existingBlob = [repository lookUpObjectByOID:entry.OID error:&error]; NSLog(@"File content: %@", existingBlob.content); ``` -------------------------------- ### Perform Git Checkout Operations with ObjectiveGit Source: https://context7.com/xiaobingtech/objective-git/llms.txt This snippet illustrates how to perform checkout operations on branches, commits, and trees using ObjectiveGit. It demonstrates configuring checkout options, including safe and force strategies, and setting up a progress callback for observing the checkout process. The code shows checking out a local branch, a specific commit (resulting in a detached HEAD), and a tree. ```objc #import NSError *error = nil; // Assuming repoURL is defined elsewhere GTRepository *repository = [GTRepository repositoryWithURL:repoURL error:&error]; // Configure checkout options with safe strategy GTCheckoutOptions *options = [GTCheckoutOptions checkoutOptionsWithStrategy:GTCheckoutStrategySafe]; // Add progress callback options.progressBlock = ^(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps) { float percentage = (float)completedSteps / totalSteps * 100; NSLog(@"Checkout progress: %.1f%% - %@", percentage, path); }; // Checkout a branch // Assuming 'develop' is an existing local branch GTBranch *branch = [repository lookUpBranchWithName:@"develop" type:GTBranchTypeLocal success:NULL error:&error]; if (branch && [repository checkoutReference:branch.reference options:options error:&error]) { NSLog(@"Checked out branch: %@", branch.name); } // Checkout a commit (detached HEAD) // Assuming commit is an existing GTCommit object GTCommit *commit = [repository lookUpObjectBySHA:@"abc123..." error:&error]; if ([repository checkoutCommit:commit options:options error:&error]) { NSLog(@"Checked out commit: %@", commit.SHA); } // Checkout a tree GTTree *tree = commit.tree; // Get the tree from the commit if ([repository checkoutTree:tree options:options error:&error]) { NSLog(@"Checked out tree: %@", tree.SHA); } // Checkout specific strategy (Force) GTCheckoutOptions *forceOptions = [GTCheckoutOptions checkoutOptionsWithStrategy:GTCheckoutStrategyForce]; // Assuming commit is an existing GTCommit object if ([repository checkoutCommit:commit options:forceOptions error:&error]) { NSLog(@"Force checkout completed"); } ``` -------------------------------- ### Manage Git Index and Stage Files in Objective-C Source: https://context7.com/xiaobingtech/objective-git/llms.txt This Objective-C code snippet illustrates how to manage the Git index using ObjectiveGit. It covers retrieving the index, checking for conflicts, adding individual files, adding all files, adding data directly, removing files, writing the index to disk, enumerating index entries, and retrieving specific entries. This functionality is crucial for preparing commits. ```objc #import NSError *error = nil; // Assume repoURL is defined elsewhere, e.g., NSURL *repoURL = [NSURL fileURLWithPath:@"/path/to/your/repo"]; GTRepository *repository = [GTRepository repositoryWithURL:repoURL error:&error]; // Get repository index GTIndex *index = [repository indexWithError:&error]; if (!index) { NSLog(@"Failed to get index: %@", error); return; } NSLog(@"Index has %lu entries", (unsigned long)index.entryCount); NSLog(@"Has conflicts: %@", index.hasConflicts ? @"YES" : @"NO"); // Add individual file to index if ([index addFile:@"src/main.m" error:&error]) { NSLog(@"File added to index"); } // Add all files (like 'git add -A') if ([index addAll:&error]) { NSLog(@"All files added to index"); } // Add data directly to index NSData *fileData = [@"Hello, World!" dataUsingEncoding:NSUTF8StringEncoding]; if ([index addData:fileData withPath:@"hello.txt" error:&error]) { NSLog(@"Data added to index"); } // Remove file from index if ([index removeFile:@"old-file.txt" error:&error]) { NSLog(@"File removed from index"); } // Write index to disk if ([index write:&error]) { NSLog(@"Index written to disk"); } // Enumerate index entries NSArray *entries = index.entries; for (GTIndexEntry *entry in entries) { NSLog(@"Entry: %@", entry.path); } // Get specific entry GTIndexEntry *entry = [index entryWithPath:@"README.md" error:&error]; if (entry) { NSLog(@"Entry found: %@", entry.path); } ``` -------------------------------- ### Set Header Search Paths for libgit2 Headers Source: https://github.com/xiaobingtech/objective-git/blob/master/README.md This build setting configures the compiler to find the libgit2 header files. Incorrect configuration can lead to 'git2/filter.h' not found errors. ```xcode External/ObjectiveGit/External/libgit2/include ``` -------------------------------- ### Manage Git Tags with ObjectiveGit Source: https://context7.com/xiaobingtech/objective-git/llms.txt This snippet demonstrates how to create and manage both lightweight and annotated Git tags using the ObjectiveGit library. It covers retrieving all tags, creating new lightweight tags, and creating annotated tags with author information and messages. It also shows how to obtain the Object ID (OID) for a tag without fully creating the tag object. ```objc #import NSError *error = nil; // Assuming repoURL is defined elsewhere GTRepository *repository = [GTRepository repositoryWithURL:repoURL error:&error]; // Get all tags NSArray *tags = [repository allTagsWithError:&error]; for (GTTag *tag in tags) { NSLog(@"Tag: %@ -> %@", tag.name, tag.target.SHA); } // Create lightweight tag // Assuming commit is an existing GTCommit object GTCommit *commit = [repository lookUpObjectBySHA:@"abc123..." error:&error]; if ([repository createLightweightTagNamed:@"v1.0.0" target:commit error:&error]) { NSLog(@"Lightweight tag created"); } // Create annotated tag GTSignature *tagger = [[GTSignature alloc] initWithName:@"John Doe" email:@"john@example.com" time:[NSDate date]]; GTTag *annotatedTag = [repository createTagNamed:@"v2.0.0" target:commit tagger:tagger message:@"Release version 2.0.0\n\nMajor update with new features" error:&error]; if (annotatedTag) { NSLog(@"Annotated tag created: %@", annotatedTag.name); NSLog(@"Tag message: %@", annotatedTag.message); } // Get OID for annotated tag (without creating tag object) GTOID *tagOID = [repository OIDByCreatingTagNamed:@"v3.0.0" target:commit tagger:tagger message:@"Version 3.0.0" error:&error]; if (tagOID) { NSLog(@"Tag OID: %@", tagOID.SHA); } ``` -------------------------------- ### Generate Diffs with ObjectiveGit Source: https://context7.com/xiaobingtech/objective-git/llms.txt Shows how to generate and analyze differences between various Git states using ObjectiveGit. This includes diffing the working directory against HEAD, comparing two commits, and applying custom diff options. ```objc #import NSError *error = nil; GTRepository *repository = [GTRepository repositoryWithURL:repoURL error:&error]; // Diff working directory to HEAD GTDiff *diff = [GTDiff diffWorkingDirectoryToHEADInRepository:repository options:nil error:&error]; if (!diff) { NSLog(@"Failed to create diff: %@", error); return; } NSLog(@"Number of deltas: %lu", (unsigned long)diff.deltaCount); // Enumerate through changes [diff enumerateDeltasUsingBlock:^(GTDiffDelta *delta, BOOL *stop) { NSLog(@"File: %@", delta.newFile.path); NSLog(@"Status: %ld", (long)delta.type); // Access file information NSLog(@"Old SHA: %@", delta.oldFile.OID.SHA); NSLog(@"New SHA: %@", delta.newFile.OID.SHA); }]; // Diff between two commits GTCommit *oldCommit = [repository lookUpObjectBySHA:@"abc123..." error:&error]; GTCommit *newCommit = [repository lookUpObjectBySHA:@"def456..." error:&error]; GTDiff *commitDiff = [GTDiff diffOldTree:oldCommit.tree withNewTree:newCommit.tree inRepository:repository options:nil error:&error]; // Configure diff options NSDictionary *diffOptions = @{ GTDiffOptionsFlagsKey: @(GTDiffOptionsFlagsIncludeUntracked | GTDiffOptionsFlagsRecurseUntrackedDirs), GTDiffOptionsContextLinesKey: @5, GTDiffOptionsPathSpecArrayKey: @[@"*.m", @"*.h"] }; GTDiff *customDiff = [GTDiff diffIndexToWorkingDirectoryInRepository:repository options:diffOptions error:&error]; ``` -------------------------------- ### Strip Frameworks Script Source: https://github.com/xiaobingtech/objective-git/blob/master/README.md A script used for stripping unnecessary slices from iOS frameworks, particularly simulator slices, to ensure App Store compliance. This is a common task when building fat frameworks for iOS. ```bash https://github.com/realm/realm-cocoa/blob/master/scripts/strip-frameworks.sh ``` -------------------------------- ### Navigate Tree Structures in Objective-Git Source: https://context7.com/xiaobingtech/objective-git/llms.txt Shows how to traverse Git tree structures, access entries by index, name, or path, and recursively enumerate all entries. This functionality is crucial for inspecting repository contents. Requires the ObjectiveGit framework. ```objc #import NSError *error = nil; GTRepository *repository = [GTRepository repositoryWithURL:repoURL error:&error]; // Get tree from commit GTCommit *commit = [repository lookUpObjectBySHA:@"abc123..." error:&error]; GTTree *tree = commit.tree; NSLog(@"Tree has %lu entries", (unsigned long)tree.entryCount); // Access entries by index for (NSUInteger i = 0; i < tree.entryCount; i++) { GTTreeEntry *entry = [tree entryAtIndex:i]; NSLog(@"Entry: %@ (SHA: %@)", entry.name, entry.OID.SHA); } // Access entry by name GTTreeEntry *entry = [tree entryWithName:@"README.md"]; if (entry) { NSLog(@"Found entry: %@", entry.name); } // Access entry by path (nested) GTTreeEntry *nestedEntry = [tree entryWithPath:@"src/main.m" error:&error]; if (nestedEntry) { NSLog(@"Found nested entry: %@", nestedEntry.path); } // Enumerate tree recursively [tree enumerateEntriesWithOptions:GTTreeEnumerationOptionPre error:&error block:^BOOL(GTTreeEntry *entry, NSString *root, BOOL *stop) { NSLog(@"Path: %@%@", root, entry.name); NSLog(@"Type: %ld", (long)entry.type); // Return YES to recurse into subdirectories, NO to skip return YES; }]; // Get all entries NSArray *entries = tree.entries; for (GTTreeEntry *entry in entries) { NSLog(@"Entry: %@ (type: %ld)", entry.name, (long)entry.type); } ``` -------------------------------- ### Clone Git Repository with Progress Tracking (Objective-C) Source: https://context7.com/xiaobingtech/objective-git/llms.txt Clones a remote Git repository to a local directory. It includes options for checkout progress tracking and transfer progress callbacks, allowing for detailed feedback during the cloning process. Requires the ObjectiveGit framework. ```objc #import NSError *error = nil; NSURL *originURL = [NSURL URLWithString:@"https://github.com/libgit2/objective-git.git"]; NSURL *localURL = [NSURL fileURLWithPath:@"/path/to/local/clone"]; // Setup checkout options with progress callback GTCheckoutOptions *checkoutOptions = [GTCheckoutOptions checkoutOptionsWithStrategy:GTCheckoutStrategySafe]; checkoutOptions.progressBlock = ^(NSString *path, NSUInteger completedSteps, NSUInteger totalSteps) { NSLog(@"Checkout progress: %@ (%lu/%lu)", path, (unsigned long)completedSteps, (unsigned long)totalSteps); }; // Configure clone options NSDictionary *cloneOptions = @{ GTRepositoryCloneOptionsCheckoutOptions: checkoutOptions }; // Clone with transfer progress tracking GTRepository *repository = [GTRepository cloneFromURL:originURL toWorkingDirectory:localURL options:cloneOptions error:&error transferProgressBlock:^(const git_transfer_progress *progress, BOOL *stop) { if (progress->total_objects > 0) { float percentage = (float)progress->received_objects / progress->total_objects * 100; NSLog(@"Transfer: %.1f%% (%u/%u objects)", percentage, progress->received_objects, progress->total_objects); } }]; if (!repository) { NSLog(@"Clone failed: %@", error.localizedDescription); return; } NSLog(@"Repository cloned successfully to: %@", repository.fileURL); ``` -------------------------------- ### Add ObjectiveGit as a Git Submodule Source: https://github.com/xiaobingtech/objective-git/blob/master/README.md This command adds the ObjectiveGit repository as a submodule to your project. It's a common practice for managing external dependencies in Git projects. ```shell git submodule add https://github.com/libgit2/objective-git.git External/ObjectiveGit ``` -------------------------------- ### Check Repository Status and File Changes in Objective-C Source: https://context7.com/xiaobingtech/objective-git/llms.txt This Objective-C code snippet demonstrates how to check the status of a Git repository using ObjectiveGit. It covers determining if the working directory is clean, enumerating file status (staged and modified), querying the status of specific files, and checking if files should be ignored. It requires the ObjectiveGit framework. ```objc #import NSError *error = nil; // Assume repoURL is defined elsewhere, e.g., NSURL *repoURL = [NSURL fileURLWithPath:@"/path/to/your/repo"]; GTRepository *repository = [GTRepository repositoryWithURL:repoURL error:&error]; // Check if working directory is clean BOOL isClean = repository.workingDirectoryClean; NSLog(@"Working directory is %@", isClean ? @"clean" : @"dirty"); // Enumerate file status NSDictionary *statusOptions = @{ GTRepositoryStatusOptionsFlagsKey: @(GTRepositoryStatusFlagsIncludeUntracked | GTRepositoryStatusFlagsRecurseUntrackedDirectories) }; [repository enumerateFileStatusWithOptions:statusOptions error:&error usingBlock:^(GTStatusDelta *headToIndex, GTStatusDelta *indexToWorkingDirectory, BOOL *stop) { if (headToIndex) { NSLog(@"Staged: %@ (status: %ld)", headToIndex.newFile.path, (long)headToIndex.status); } if (indexToWorkingDirectory) { NSLog(@"Modified: %@ (status: %ld)", indexToWorkingDirectory.newFile.path, (long)indexToWorkingDirectory.status); } }]; // Query status of specific file NSString *filePath = @"src/main.m"; BOOL success; GTFileStatusFlags fileStatus = [repository statusForFile:filePath success:&success error:&error]; if (success) { if (fileStatus & GTFileStatusModifiedInWorktree) { NSLog(@"%@ is modified in working directory", filePath); } if (fileStatus & GTFileStatusNewInIndex) { NSLog(@"%@ is staged as new", filePath); } if (fileStatus & GTFileStatusCurrent) { NSLog(@"%@ is up to date", filePath); } } // Check if file should be ignored NSURL *fileURL = [repository.fileURL URLByAppendingPathComponent:@".DS_Store"]; BOOL shouldIgnore = [repository shouldFileBeIgnored:fileURL success:&success error:&error]; if (success) { NSLog(@"File should%@ be ignored", shouldIgnore ? @"" : @" not"); } ``` -------------------------------- ### Create New Git Commit (Objective-C) Source: https://context7.com/xiaobingtech/objective-git/llms.txt Creates a new Git commit in a repository. This involves adding files to the index, writing the index to a tree, and then creating the commit with specified message, author, and parent commits. It updates the HEAD reference to point to the new commit. Requires the ObjectiveGit framework and a valid repository URL. ```objc #import NSError *error = nil; GTRepository *repository = [GTRepository repositoryWithURL:repoURL error:&error]; // Get the repository index and add files GTIndex *index = [repository indexWithError:&error]; if (![index addFile:@"README.md" error:&error]) { NSLog(@"Failed to add file: %@", error); return; } if (![index write:&error]) { NSLog(@"Failed to write index: %@", error); return; } // Create tree from index GTTree *tree = [index writeTree:&error]; if (!tree) { NSLog(@"Failed to create tree: %@", error); return; } // Create signature for author and committer GTSignature *signature = [[GTSignature alloc] initWithName:@"John Doe" email:@"john@example.com" time:[NSDate date]]; // Get parent commit (HEAD) GTReference *headRef = [repository headReferenceWithError:&error]; GTCommit *parentCommit = [repository lookUpObjectByOID:headRef.targetOID error:&error]; // Create the commit GTCommit *newCommit = [repository createCommitWithTree:tree message:@"Initial commit\n\nAdded README file" author:signature committer:signature parents:parentCommit ? @[parentCommit] : nil updatingReferenceNamed:@"HEAD" error:&error]; if (newCommit) { NSLog(@"Created commit: %@", newCommit.SHA); } else { NSLog(@"Failed to create commit: %@", error); } ``` -------------------------------- ### Read Commit Information (Objective-C) Source: https://context7.com/xiaobingtech/objective-git/llms.txt Retrieves and displays detailed information about a specific Git commit, including its SHA, author, committer, date, message, and associated tree. It also shows how to access parent commits. Requires the ObjectiveGit framework and a valid repository URL. ```objc #import NSError *error = nil; GTRepository *repository = [GTRepository repositoryWithURL:repoURL error:&error]; // Lookup commit by SHA NSString *commitSHA = @"8496071c1b46c854b31185ea97743be6a8774479"; GTCommit *commit = [repository lookUpObjectBySHA:commitSHA error:&error]; if (!commit) { NSLog(@"Failed to find commit: %@", error); return; } // Read commit properties NSLog(@"Commit SHA: %@", commit.SHA); NSLog(@"Message: %@", commit.message); NSLog(@"Summary: %@", commit.messageSummary); NSLog(@"Details: %@", commit.messageDetails); NSLog(@"Date: %@", commit.commitDate); // Read author information GTSignature *author = commit.author; NSLog(@"Author: %@ <%@>", author.name, author.email); NSLog(@"Author date: %@", author.time); // Read committer information GTSignature *committer = commit.committer; NSLog(@"Committer: %@ <%@>", committer.name, committer.email); // Access tree and parents NSLog(@"Tree SHA: %@", commit.tree.SHA); NSLog(@"Parent count: %lu", (unsigned long)commit.parents.count); NSLog(@"Is merge commit: %@", commit.merge ? @"YES" : @"NO"); // Iterate through parent commits for (GTCommit *parent in commit.parents) { NSLog(@"Parent: %@", parent.SHA); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.