pcottle/learnGitBranching · warning · CommandResult
git-status-nothing-staged
Error message
git-status-nothing-staged
What it means
Thrown by commit when the staging area is empty: after handling git commit -a (which stages modified files first), there are still no staged changes, so there is nothing to commit. Mirrors git's 'no changes added to commit' / 'nothing to commit'.
Source
Thrown at src/js/git/index.js:1687
);
this.setTargetLocation(this.HEAD, newCommit);
return newCommit;
};
GitEngine.prototype.commit = function(options) {
options = options || {};
// Simulated staging gate: only active when a level engages the changes
// model. This is what makes `git add` a required step in the staging levels.
var changedFiles = null;
if (this.changesModelEngaged) {
if (options.all) {
// git commit -a / --all: stage everything modified first
this.addFiles(null);
}
if (!this.hasStagedChanges()) {
throw new CommandResult({
msg: intl.str('git-status-nothing-staged')
});
}
changedFiles = this.getStagedChanges().sort();
}
var targetCommit = this.getCommitFromRef(this.HEAD);
var id = null;
// if we want to amend, go one above
if (options.isAmend) {
targetCommit = this.resolveID('HEAD~1');
id = this.rebaseAltID(this.getCommitFromRef('HEAD').get('id'));
}
var commitOptions = changedFiles ? { changedFiles: changedFiles } : {};
var newCommit = this.makeCommit([targetCommit], id, commitOptions);
if (this.getDetachedHead() && this.mode === 'git') {View on GitHub (pinned to 5b09d0ff96)
Solutions
- Stage files first with add/addFiles (git add .)
- If files are modified, use git commit -a to auto-stage them
- Skip the commit when getStagedChanges() is empty
Example fix
// before git commit // nothing staged // after git add . git commit
Defensive patterns
Strategy: validation
Validate before calling
if (engine.changesModelEngaged && !engine.hasStagedChanges()) { /* nothing to commit; stage or skip */ } Try / catch
try { engine.commit(options); } catch (e) { if (e instanceof CommandResult) return; throw e; } Prevention
- git add before commit
- Use -a when modified files should be included
When it happens
Trigger: Calling commit with changesModelEngaged true, options.all not staging anything new (or absent), and hasStagedChanges() returning false — e.g. git commit with nothing staged, or git commit -a with no modified files.
Common situations: Double-committing in a level; forgetting git add after editing files; committing when working tree is clean.
Related errors
- git-error-options
- git-error-staging
- this.getStatusMsg()
- git-error-exist
- cannot fetch to ' + ref + ' when checked out on ' + ref
AI-assisted analysis of pcottle/learnGitBranching@5b09d0ff96 (2026-08-27).
Data as JSON: /api/errors/41aa04d917828cfc.
Report an issue: GitHub.