组合 git `continue` 命令
Combined git `continue` command
不同的是我可能需要 运行:
git rebase --continue
git cherry-pick --continue
git revert --continue
在每种情况下,我的命令行都在提醒我我处于中间状态(rebase/cp/revert),所以我很清楚它知道哪个处于活动状态。
所以感觉在概念上可能有一个命令 git continue
将继续当前处于活动状态的操作,从而节省一些繁琐的输入?
- A) 这个命令是否已经存在(在这种情况下,它是什么,它支持什么?
- B) 如果我愿意,我怎么能自己写这个命令呢? (也许有别名?)
据我所知,这样的命令不存在。但是,您可以为此创建一个脚本,例如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
,您可能也想涵盖这些标志。
除了@alfunx 的回答之外,我可能会建议进行以下更改:
我没有执行 repo_path=$(git rev-parse --git-dir 2>/dev/null)
,所以 git 的 return 代码和日志被忽略,我将脚本更改为:
#!/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
现在这个脚本...
- returns 相应的退出代码(例如,
128
表示不是 git 存储库等)和来自 git 二进制文件本身的错误消息(如 fatal: not a git repository (or any of the parent directories): .git
)
echo "No something in progress?"
如果没有任何事情发生。
不同的是我可能需要 运行:
git rebase --continue
git cherry-pick --continue
git revert --continue
在每种情况下,我的命令行都在提醒我我处于中间状态(rebase/cp/revert),所以我很清楚它知道哪个处于活动状态。
所以感觉在概念上可能有一个命令 git continue
将继续当前处于活动状态的操作,从而节省一些繁琐的输入?
- A) 这个命令是否已经存在(在这种情况下,它是什么,它支持什么?
- B) 如果我愿意,我怎么能自己写这个命令呢? (也许有别名?)
据我所知,这样的命令不存在。但是,您可以为此创建一个脚本,例如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
,您可能也想涵盖这些标志。
除了@alfunx 的回答之外,我可能会建议进行以下更改:
我没有执行 repo_path=$(git rev-parse --git-dir 2>/dev/null)
,所以 git 的 return 代码和日志被忽略,我将脚本更改为:
#!/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
现在这个脚本...
- returns 相应的退出代码(例如,
128
表示不是 git 存储库等)和来自 git 二进制文件本身的错误消息(如fatal: not a git repository (or any of the parent directories): .git
) echo "No something in progress?"
如果没有任何事情发生。