带有特定字符串的前缀 Git 状态文件路径

Prefix Git Status File Path with particular string

我在(存储库的)根目录下执行 git status --short,它列出了相对于根目录的文件路径,如下所示:

M NumericalProgramming1Src/FloatingPointNumber.md
M NumericalProgramming1Src/NumericalProgramming.md

我想在所有路径前加上存储在变量中的值:CustomPrefix=My/Path/To/Root/ 如下

M My/Path/To/Root/NumericalProgramming1Src/FloatingPointNumber.md
M My/Path/To/Root/NumericalProgramming1Src/NumericalProgramming.md

我怎样才能做到这一点?

注意:有时 git status 开头有多个字符。

使用 awk 只需调用:

custom="/test/"
git status --short | awk -v cp="$custom" '{=cp}1'

例如,当 git status --short 产生

M org/languagetool/resource/de/added.txt

以上命令产生:

M /test/org/languagetool/resource/de/added.txt