组合 git `continue` 命令

问题描述 投票:0回答:3

我可能需要运行:

  • git rebase --continue
  • git cherry-pick --continue
  • git revert --continue

在每种情况下,我的命令行都会提醒我,我处于中间状态(rebase/cp/revert),因此我很清楚它知道哪个是活动的。

所以感觉概念上可能有一个命令

git continue
它将继续当前活动的操作,从而节省一些繁琐的打字?

  • A)这个命令是否已经存在(在这种情况下,它是什么,它支持什么?
  • B) 如果我愿意的话,我怎么能自己写这个命令呢? (也许有别名?)
git alias
3个回答
4
投票

除了@alfunx的回答之外,我可能会建议进行这样的更改:

我没有这样做

repo_path=$(git rev-parse --git-dir 2>/dev/null)
从而忽略 git 的返回码和日志,而是将脚本更改为:

#!/usr/bin/env bash

repo_path=$(git rev-parse --git-dir)

if [ $? -ne 0 ]; then
    exit $?
fi

if [ -d "${repo_path}/rebase-merge" ]; then
    git rebase --continue
elif [ -d "${repo_path}/rebase-apply" ]; then
    git rebase --continue
elif [ -f "${repo_path}/MERGE_HEAD" ]; then
    git merge --continue
elif [ -f "${repo_path}/CHERRY_PICK_HEAD" ]; then
    git cherry-pick --continue
elif [ -f "${repo_path}/REVERT_HEAD" ]; then
    git revert --continue
else
    echo "No something in progress?"
fi

现在这个脚本...

  1. 返回相应的退出代码(例如,
    128
    表示不是 git 存储库等)和来自 git 二进制文件本身的错误消息(如
    fatal: not a git repository (or any of the parent directories): .git
  2. echo "No something in progress?"
    如果没有发生任何事情的话。

4
投票

据我所知,这样的命令不存在。但是,您可以为此创建一个脚本,例如

git-continue

#!/usr/bin/env bash

repo_path=$(git rev-parse --git-dir 2>/dev/null)

if [ -d "${repo_path}/rebase-merge" ]; then
    git rebase --continue
elif [ -d "${repo_path}/rebase-apply" ]; then
    git rebase --continue
elif [ -f "${repo_path}/MERGE_HEAD" ]; then
    git merge --continue
elif [ -f "${repo_path}/CHERRY_PICK_HEAD" ]; then
    git cherry-pick --continue
elif [ -f "${repo_path}/REVERT_HEAD" ]; then
    git revert --continue
fi

将脚本放在

$PATH
中的某个位置,然后就可以使用
git continue

请注意,还有类似的标志,如

--continue
,例如
--abort
--skip
--quit
,您可能也想覆盖它们。


0
投票

如果你想将其作为 powershell 函数,这里是:

# Continues the ongoing git operation.
function git-continue {
    $repoPath = git rev-parse --git-dir

    if ($LASTEXITCODE -ne 0) {
        exit $LASTEXITCODE
    }

    if (Test-Path -Path (Join-Path $repoPath "rebase-merge") -PathType Container) {
        git rebase --continue
    }
    elseif (Test-Path -Path (Join-Path $repoPath "rebase-apply") -PathType Container) {
        git rebase --continue
    }
    elseif (Test-Path -Path (Join-Path $repoPath "MERGE_HEAD") -PathType Leaf) {
        git merge --continue
    }
    elseif (Test-Path -Path (Join-Path $repoPath "CHERRY_PICK_HEAD") -PathType Leaf) {
        git cherry-pick --continue
    }
    elseif (Test-Path -Path (Join-Path $repoPath "REVERT_HEAD") -PathType Leaf) {
        git revert --continue
    }
    else {
        Write-Host "fatal: No operation in progress?"
    }
}

可以使用以下方法将其设为别名:

git config --global alias.continue "!pwsh -command 'git-continue'"


受到@ik1ne的回答的启发

© www.soinside.com 2019 - 2024. All rights reserved.