如何在 shell 脚本中使用 git-stash --keep-index 而不会发生冲突

ELL*_*BLE 5 git shell scripting git-stash

我正在尝试自动化 git-repository 上的特定操作(typedoc生成 TypeScript 文档的命令);但我需要该命令才能“查看”实际进行的更改。任何未暂存的更改都需要从命令中“隐藏”。

我当前的方法是尝试自动化 git-stash,以便它隐藏任何未跟踪的文件和未暂存的更改,然后运行命令,然后弹出该存储。该脚本的核心内容是:

stash_working=_no

git update-index --refresh
if git diff-index HEAD -- .':!Documentation/'; then
   stash_working=_yes
fi

if [ "$stash_working" != "_no" ]; then
   git stash push --include-untracked --keep-index -m "AUTOMATED STASH" \
       -- .':!Documentation/'
fi

typedoc
typedoc_exit_status=$?

if [ "$stash_working" != "_no" ]; then
   git stash pop
fi

exit $typedoc_exit_status
Run Code Online (Sandbox Code Playgroud)

不幸的是,这并没有按预期工作:特别是,尽管“未包含”在存储中,但存储的更改......在弹出时会干扰自身(?)。例如,如果分阶段内容(我确实想要在文档中看到)包含此行,

 * This is some fake documentation for testing purposes.
Run Code Online (Sandbox Code Playgroud)

...但是有一个未分阶段的更改将其更新为

 * THIS IS A CHANGE TO THAT DOCUMENTATION
Run Code Online (Sandbox Code Playgroud)

...然后我遇到以下冲突,并且git stash pop失败:

 * This is some fake documentation for testing purposes.
Run Code Online (Sandbox Code Playgroud)

我也尝试过git stash pop --index,但在这种情况下具有相同的效果。

是否有一种以 Git 为中心的方法(即不编写临时工作目录的创建脚本、签出、运行 docgen、将文档复制回原始项目、事物类型)来改进这种自动化,以便这样的合并- 不会发生冲突,并且工作目录透明地保持在运行期间的状态