Shelljs exec 在 git cherry-pick 上失败

Shelljs exec failed on git cherry-pick

我有一个脚本可以使用 shelljs.

挑选提交

这是我的 LOC,它使用 shelljs.

进行挑选
shell.exec('git cherry-pick commitid -X theirs');
Note: commitid = sha of commit I want to cherry-pick.

shelljs 抛出以下错误:

fatal: bad object: commitid 

例如

fatal: bad object: 7854484884 (commitid)

我发现了问题。

我的项目结构是这样的:

project1 (git repo)
  cherrypick.js
  project2 (another git repo)

我想在 project2 中挑选一个提交并将其合并到不同的分支中。

但是写的代码是在project1中。因此我不得不添加这一行并且它起作用了。

shell.exec('cd project2');
shell.exec('git cherry-pick commitid -X theirs');