Get affected files in a git commit
Install git-affected-files
using npm:
npm install --save git-affected-files
const gitAffectedFiles = require('git-affected-files');
// Get affected files for last commit
gitAffectedFiles()
.then(files => {
console.log(files);
/*
[
{status: 'A', filename: 'a/new/file'},
{status: 'M', filename: 'a/modified/file'},
{status: 'D', filename: 'a/deleted/file'},
]
*/
});
// Get affected files for specific commit:
gitAffectedFiles('6ba8b08')
.then(files => {
console.log(files);
/*
[
{status: 'A', filename: '.editorconfig'},
{status: 'A', filename: '.gitignore'},
...
]
*/
});
Name | Type | Description |
---|---|---|
hash | String |
Git commit sha hash string |
options | Object |
Provided options are passed to execa , used to set cwd and similar |
Returns: Promise<Array<Object>>
MIT © Joakim Carlstein