{"record":{"id":"f5cfa3fd1586e565","repo":"pcottle/learnGitBranching","slug":"git-error-already-exists","errorCode":null,"errorMessage":"git-error-already-exists","messagePattern":"git-error-already-exists","errorType":"exception","errorClass":"GitError","httpStatus":null,"severity":"error","filePath":"src/js/git/commands.js","lineNumber":227,"sourceCode":"  },\n\n  cherrypick: {\n    displayName: 'cherry-pick',\n    regex: /^git +cherry-pick($|\\s)/,\n    description: 'Apply changes from existing commits',\n    execute: function(engine, command) {\n      var commandOptions = command.getOptionsMap();\n      var generalArgs = command.getGeneralArgs();\n\n      command.validateArgBounds(generalArgs, 1, Number.MAX_VALUE);\n\n      var set = Graph.getUpstreamSet(engine, 'HEAD');\n      // first resolve all the refs (as an error check)\n      var toCherrypick = generalArgs.map(function (arg) {\n        var commit = engine.getCommitFromRef(arg);\n        // and check that its not upstream\n        if (set[commit.get('id')]) {\n          throw new GitError({\n            msg: intl.str(\n              'git-error-already-exists',\n              { commit: commit.get('id') }\n            )\n          });\n        }\n        return commit;\n      }, this);\n\n      engine.setupCherrypickChain(toCherrypick);\n    }\n  },\n\n  gc: {\n    displayName: 'gc',\n    regex: /^git +gc($|\\s)/,\n    description: 'Cleanup unnecessary files and optimize the repository',\n    execute: function(engine, command) {","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/pcottle/learnGitBranching/blob/5b09d0ff9678cad164f5a7488a279a44f90d7256/src/js/git/commands.js#L209-L245","documentation":"Cherry-pick refuses a commit that is already an ancestor of HEAD (in Graph.getUpstreamSet of HEAD). Mirrors git's 'The previous cherry-pick is now empty' / already-applied behavior; the msg key is git-error-already-exists.","triggerScenarios":"git cherry-pick <sha> where <sha> is reachable from HEAD — e.g. cherry-picking C2 while sitting on a branch that already contains C2.","commonSituations":"Re-applying a commit after a rebase already incorporated it; copy-pasting an old SHA.","solutions":["Verify the commit isn't upstream: git log / check Graph.getUpstreamSet before cherry-picking","Skip that commit — it's already applied","If you want a duplicate commit, the simulator deliberately disallows it"],"exampleFix":"// before\ngit checkout main; git cherry-pick C2  // C2 already in main\n// after\ngit log --graph  # confirm, then cherry-pick only missing commits like C3","handlingStrategy":"validation","validationCode":"var upstream = Graph.getUpstreamSet(engine, 'HEAD'); var c = engine.getCommitFromRef(arg); if (upstream[c.get('id')]) skip(arg);","typeGuard":"function isAlreadyApplied(engine, sha) { return !!Graph.getUpstreamSet(engine, 'HEAD')[sha]; }","tryCatchPattern":null,"preventionTips":["Filter candidate SHAs against upstream set before cherry-picking","After rebases, re-derive cherry-pick lists from git log"],"tags":["git","cherry-pick","ancestry"],"backgroundTag":"commit-already-applied","analyzedSha":"5b09d0ff9678cad164f5a7488a279a44f90d7256","analyzedAt":"2026-08-27T13:53:49.057Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}