{"record":{"id":"41aa04d917828cfc","repo":"pcottle/learnGitBranching","slug":"git-status-nothing-staged","errorCode":null,"errorMessage":"git-status-nothing-staged","messagePattern":"git-status-nothing-staged","errorType":"validation","errorClass":"CommandResult","httpStatus":null,"severity":"warning","filePath":"src/js/git/index.js","lineNumber":1687,"sourceCode":"  );\n  this.setTargetLocation(this.HEAD, newCommit);\n\n  return newCommit;\n};\n\nGitEngine.prototype.commit = function(options) {\n  options = options || {};\n\n  // Simulated staging gate: only active when a level engages the changes\n  // model. This is what makes `git add` a required step in the staging levels.\n  var changedFiles = null;\n  if (this.changesModelEngaged) {\n    if (options.all) {\n      // git commit -a / --all: stage everything modified first\n      this.addFiles(null);\n    }\n    if (!this.hasStagedChanges()) {\n      throw new CommandResult({\n        msg: intl.str('git-status-nothing-staged')\n      });\n    }\n    changedFiles = this.getStagedChanges().sort();\n  }\n\n  var targetCommit = this.getCommitFromRef(this.HEAD);\n  var id = null;\n\n  // if we want to amend, go one above\n  if (options.isAmend) {\n    targetCommit = this.resolveID('HEAD~1');\n    id = this.rebaseAltID(this.getCommitFromRef('HEAD').get('id'));\n  }\n\n  var commitOptions = changedFiles ? { changedFiles: changedFiles } : {};\n  var newCommit = this.makeCommit([targetCommit], id, commitOptions);\n  if (this.getDetachedHead() && this.mode === 'git') {","sourceCodeStart":1669,"sourceCodeEnd":1705,"githubUrl":"https://github.com/pcottle/learnGitBranching/blob/5b09d0ff9678cad164f5a7488a279a44f90d7256/src/js/git/index.js#L1669-L1705","documentation":"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'.","triggerScenarios":"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.","commonSituations":"Double-committing in a level; forgetting git add after editing files; committing when working tree is clean.","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"],"exampleFix":"// before\ngit commit // nothing staged\n// after\ngit add .\ngit commit","handlingStrategy":"validation","validationCode":"if (engine.changesModelEngaged && !engine.hasStagedChanges()) { /* nothing to commit; stage or skip */ }","typeGuard":null,"tryCatchPattern":"try { engine.commit(options); } catch (e) { if (e instanceof CommandResult) return; throw e; }","preventionTips":["git add before commit","Use -a when modified files should be included"],"tags":["git","commit","staging","empty-stage"],"backgroundTag":"git-nothing-to-commit","analyzedSha":"5b09d0ff9678cad164f5a7488a279a44f90d7256","analyzedAt":"2026-08-27T13:53:49.057Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}