
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
git-changed-files
Advanced tools
Get the change between any of your branch and current branch of a `git` repository
Get the committed and uncommitted files list between your any of your branch and current branch of a
git
repository
To add it to devDependencies
yarn add git-changed-files --dev
or
npm install --save-dev git-changed-files
const gitChangedFiles = require('git-changed-files');
(async() => {
let committedGitFiles = await gitChangedFiles();
console.log(committedGitFiles);
})().catch((err) => {
console.log(err);
});
/* Expected: { committedFiles: [ '.editorconfig', '.travis.yml', 'destroy.js', 'index.js' ],
unCommittedFiles: ['index.js'] }
*/
(async() => {
let committedGitFiles = await gitChangedFiles({ formats: ['*.yml'] });
console.log(committedGitFiles);
})().catch((err) => {
console.log(err);
});
/* Expected: { committedFiles: [ '.travis.yml'],
unCommittedFiles: [] }
*/
(async() => {
let committedGitFiles = await gitChangedFiles({ formats: ['!*.yml'] });
console.log(committedGitFiles);
})().catch((err) => {
console.log(err);
});
/* Expected: { committedFiles: [ '.editorconfig', 'destroy.js', 'index.js' ],
unCommittedFiles: ['index.js'] }
*/
(async() => {
let committedGitFiles = await gitChangedFiles({ diffFilter: 'A' });
console.log(committedGitFiles);
})().catch((err) => {
console.log(err);
});
/* Expected: { committedFiles: ['destroy.js'],
unCommittedFiles: [] }
*/
(async() => {
let committedGitFiles = await gitChangedFiles({ showStatus: true });
console.log(committedGitFiles);
})().catch((err) => {
console.log(err);
});
/*
Expected:
{
committedFiles: [
{
fileName: '.editorconfig',
status: 'Modified'
},
{
fileName: '.travis.yml'
status: 'Modified'
},
{
fileName: 'destroy.js'
status: 'Added'
},
{
fileName: 'index.js'
status: 'Modified'
}
],
unCommittedFiles: [
{
fileName: 'index.js'
status: 'Modified'
}
]
}
*/
(async() => {
let uncommittedGitFiles = await gitChangedFiles({ showCommitted: false });
console.log(uncommittedGitFiles);
})().catch((err) => {
console.log(err);
});
// Expected: { unCommittedFiles: ['index.js'] }
(async() => {
let committedGitFiles = await gitChangedFiles({ showUnCommitted: false });
console.log(committedGitFiles);
})().catch((err) => {
console.log(err);
});
// Expected: { committedFiles: [ '.editorconfig', '.travis.yml', 'destroy.js', 'index.js' ] }
Returns Promise<Array[]|String>
.
Type: Object
Type: string
Default: master
baseBranch to compare with you current HEAD.
Example: if baseBranch is master, then the list of files that are changed from master to your current HEAD in local will be displayed.
Type: string
| string[]
Default: false
Filters passed filetypes. If need all filetypes pass false
or specify the filetypes in array.
Example:
[*.js]
[!*.js]
Type: string
Default: ACDMRTUXB
Diff filters :
Refer More here
Type: boolean
Default: false
To show the type of file change in the result.
Example: If showStatus is true then output will be
[{ filename: '.editorconfig', status: 'Deleted' }]
Type: boolean
Default: true
Examples:
Case 1:
By default, it lists all the changed files.
{ committedFiles: [ '.editorconfig', '.travis.yml', 'destroy.js', 'index.js' ], unCommittedFiles: ['index.js'] }
Case 2:
If showUnCommitted
is false then output will be
{ committedFiles: [ '.editorconfig', '.travis.yml', 'destroy.js', 'index.js' ] }
Case 3:
If showCommitted
is false then output will be
{ unCommittedFiles: ['index.js'] }
Case 4:
If both options are false then it will throw an error.
Either showCommitted or showUnCommitted must be true
If you changed a file and committed then again if you changed the same file, it will be present in both committed and uncommitted files list.
MIT
FAQs
Get the change between any of your branch and current branch of a `git` repository
We found that git-changed-files demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.