Combined git `continue` command

蹲街弑〆低调 提交于 2019-12-01 21:52:57

问题


Variously I might need to run:

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

In each case, my command line is reminding me that I'm mid-(rebase/cp/revert) so it's clear to me that it knows which one is active.

So it feels like there could conceptually be a command git continue which will continue whichever operation is currently active, thus saving some tedious typing?

  • A) Does this command exist already (in which case, what is it, and what does it support?
  • B) How could I write this command myself, if I were so inclined? (Maybe with aliases?)

回答1:


Such a command does not exist, to my knowledge. However you could create a script for that, called e.g. 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

Put the script somewhere in your $PATH, and then you can use git continue.

Note that there are similar flags like --continue, for example --abort, --skip, --quit, which you might want to cover as well.




回答2:


In addition to @alfunx's answer, I might suggest this change:

Instead of doing repo_path=$(git rev-parse --git-dir 2>/dev/null) so git's return code & log is ignored, I changed the script to this:

#!/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

Now this script...

  1. returns corresponding exit code(for example, 128 for not being a git repository, etc) and error message from git binary itself(like fatal: not a git repository (or any of the parent directories): .git)
  2. echo "No something in progress?" if there was nothing going on.


来源:https://stackoverflow.com/questions/52987918/combined-git-continue-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!