Commits & Staging
Stage files
Section titled “Stage files”// Stage specific pathstry repo.stage(paths: ["README.md", "Sources/MyFile.swift"])
// Stage everything (git add -A)try repo.stageAll()Unstage files
Section titled “Unstage files”try repo.unstage(paths: ["README.md"])Commit
Section titled “Commit”let author = Signature(name: "Alice", email: "alice@example.com")let commit = try repo.commit(message: "feat: add login screen", author: author)print(commit.oid.string) // full SHAThe committer is set to the same value as the author. Both timestamp from the current time.
Walk commit history
Section titled “Walk commit history”Gitty exposes history as an AsyncSequence via CommitLog:
// Last 20 commitslet commits = try repo.log(limit: 20)for commit in commits { print(commit.oid.shortString, commit.message)}
// From a specific reflet commits = try repo.log(from: "origin/main", limit: 50)Commit model
Section titled “Commit model”public struct Commit: Sendable, Identifiable { public let oid: OID public let message: String public let author: Signature public let committer: Signature public let parentOIDs: [OID]}Cherry-pick
Section titled “Cherry-pick”let result = try repo.cherryPick(commit)switch result {case .success(let commit): print("Picked:", commit.oid.shortString)case .conflict: print("Conflicts — resolve and commit")}