core-agent-ide/codex-rs/utils/git
2025-11-18 15:26:09 +00:00
..
src feat: git branch tooling (#6831) 2025-11-18 15:26:09 +00:00
Cargo.toml Reasoning level update (#6586) 2025-11-13 06:24:36 +00:00
README.md chore: merge git crates (#5909) 2025-10-29 12:11:44 +00:00

codex-git

Helpers for interacting with git, including patch application and worktree snapshot utilities.

use std::path::Path;

use codex_git::{
    apply_git_patch, create_ghost_commit, restore_ghost_commit, ApplyGitRequest,
    CreateGhostCommitOptions,
};

let repo = Path::new("/path/to/repo");

// Apply a patch (omitted here) to the repository.
let request = ApplyGitRequest {
    cwd: repo.to_path_buf(),
    diff: String::from("...diff contents..."),
    revert: false,
    preflight: false,
};
let result = apply_git_patch(&request)?;

// Capture the current working tree as an unreferenced commit.
let ghost = create_ghost_commit(&CreateGhostCommitOptions::new(repo))?;

// Later, undo back to that state.
restore_ghost_commit(repo, &ghost)?;

Pass a custom message with .message("…") or force-include ignored files with .force_include(["ignored.log".into()]).