📦 @simbo/git-changes
A library to read, parse and provide Git changes information for a local repository.
Requires Node.js ^24.15.0 || >=26.0.0.
Install @simbo/git-changes from the npm registry:
npm i [-D] @simbo/git-changes
import { getGitChanges, GitChangeStatus } from '@simbo/git-changes';
// get a map of changed files in the repository located at /path/to/repo
const changes = await getGitChanges('/path/to/repo');
for (const change of changes.values()) {
if (change.staged === GitChangeStatus.Renamed) {
console.log(`${change.originPath} → ${change.path}`);
}
}
getGitChanges() accepts any directory inside the repository and defaults to
the current working directory. It reads git status --porcelain --null and
returns a ReadonlyMap from file path to change. Example:
Map {
'new.txt' => { path: 'new.txt', originPath: 'old.txt', staged: 'R', unstaged: undefined },
'src/index.ts' => { path: 'src/index.ts', staged: 'M', unstaged: 'M' },
'docs/draft.md' => { path: 'docs/draft.md', staged: undefined, unstaged: '?' },
}
Each change has these properties:
| Property | Description |
|---|---|
path |
File path relative to the repository root; the new path for renames/copies. |
originPath |
Original path relative to the repository root; only for renames/copies. |
staged |
Status in the index, or undefined if the file has no staged change. |
unstaged |
Status in the working tree, or undefined if it has no unstaged change. |
GitChangeStatus |
Value | Meaning |
|---|---|---|
Added |
A |
File was added. |
Modified |
M |
File was modified. |
TypeChanged |
T |
File type changed, such as file to symlink. |
Deleted |
D |
File was deleted. |
Renamed |
R |
File was renamed; see originPath. |
Copied |
C |
File was copied; see originPath. |
Unmerged |
U |
File has merge conflicts; set for both fields. |
Untracked |
? |
File is not tracked; only set for unstaged. |
status.showUntrackedFiles Git configuration. Ignored files are not listed.status.renames=copies).staged and unstaged set to Unmerged.parseGitStatusOutput() and parseGitChangeStatus()
are exported to parse existing git status --porcelain --null output.For a complete API reference, see the documentation.