reset
Remove files from the staging area (index).
GitClient Method
Section titled “GitClient Method”await git.reset(filepath?: string | string[]): Promise<string[]>Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
filepath | string | string[] | File path(s) to unstage. If omitted, unstages all files. |
Returns
Section titled “Returns”Returns an array of file paths that were unstaged.
Low-level Function
Section titled “Low-level Function”import { reset } from '@keydown-app/ts-git';
await reset({ fs, dir, filepath?}): Promise<{ unstaged: string[] }>Parameters
Section titled “Parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
fs | FSAdapter | required | Filesystem adapter |
dir | string | required | Working directory path |
gitdir | string | join(dir, '.git') | Git directory path |
filepath | string | string[] | undefined | File path(s) to unstage |
Example
Section titled “Example”import { GitClient, MemoryFSAdapter } from '@keydown-app/ts-git';
const fs = new MemoryFSAdapter();const git = new GitClient({ fs, dir: '/my-repo', defaultBranch: 'main' });
await git.init();
// Create initial commitawait fs.writeFile('/my-repo/README.md', '# Project', 'utf8');await git.add('README.md');await git.commit('Initial commit', { name: 'John Doe', email: 'john@example.com',});
// Stage some changesawait fs.writeFile('/my-repo/README.md', '# Updated Project', 'utf8');await fs.writeFile('/my-repo/new.txt', 'new file', 'utf8');await git.add('README.md');await git.add('new.txt');
// Check status - both stagedconst status1 = await git.status('README.md');console.log(status1); // 'modified'
// Unstage a single fileawait git.reset('README.md');
// Check status - README.md is unstagedconst status2 = await git.status('README.md');console.log(status2); // '*modified'
// new.txt is still stagedconst status3 = await git.status('new.txt');console.log(status3); // 'added'
// Unstage all remaining filesawait git.reset();
// Both are now unstagedconst status4 = await git.status('new.txt');console.log(status4); // '*added'