是否可以通过 gradle. 的 grgit 插件只提交一个文件?

Is it possible to commit only one file through grgit plugin for gradle.?

是否可以通过 gradle 的 grgit 插件只提交一个文件?

我已经修改了 version.properties 文件,我只需要使用 grgit 插件将该特定文件提交回 git。

但是当我提交回 git 时,整个项目正在提交回 git 分支。

我的代码

task pushToGit
{
    def grgit = org.ajoberstar.grgit.Grgit.open(dir: '.')
    grgit.commit(message: 'Committing Version Property Changes', all: true)
    grgit.push(force: true)
}

grgit.commit 上的 all 选项类似于 git commit -a 标志。它将提交对所有跟踪文件的更改。只提交一个,需要先添加到索引,再提交。

task pushToGit
{
    def grgit = org.ajoberstar.grgit.Grgit.open(dir: '.')
    grgit.add(patterns: ['version.properties'])
    grgit.commit(message: 'Committing Version Property Changes')
    grgit.push(force: true) // not sure I would recommend this
}