Git:在 rebase 期间防止提交

标签 git bash macos rebase

当我在交互式 rebase 期间不小心执行了 git commit --amend 时,我知道如何轻松“修复”此状态。但我想知道是否有人有任何复杂程度的解决方案,可以让我配置 git/terminal/bash 来阻止我执行此操作。

我只是在使用 Mac OSX 终端。如果解决方案需要它们,我愿意接受其他终端程序。

1 @: master$ git pull
2 @: master$ git checkout my/feature/branch
3 @: my/feature/branch$ git rebase -i master
// There are merge conflicts
// I fix them, then
4 @: my/feature/branch$ git add .
// Then what I should do is:
5correct @: my/feature/branch$ git rebase --continue
// But instead, just due to dumb muscle memory, I do:
5incorrect @: my/feature/branch$ git commit --amend

我可以轻松修复损坏的结果状态。我只是想弄清楚是否有一种方法可以配置一些东西来防止我在 rebase 过程中执行 5incorrect 命令。

最佳答案

您可以将以下本地预提交 Hook 添加为 .git/hooks/pre-commit:

#!/bin/bash
set -e
shopt -s extglob

if [[ -d `git rev-parse --git-path rebase-merge` \
   || -d `git rev-parse --git-path rebase-apply` ]]; then
  read -p 'Rebase in progress, continue? '
  [[ ${REPLY,,} == @(y|yes) ]]
fi

然后只需 chmod +x .git/hooks/pre-commit 就可以了。如果 rebase 正在进行中,那么系统会提示您继续或按 ctrl-c 或只是输入或对您来说更方便的内容,脚本/提交将停止。

关于Git:在 rebase 期间防止提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42492248/

相关文章:

eclipse - JOGL 抛出 ClassNotFoundException?

regex - grep 在 OSX 上的工作方式是否不同

git - 使用 .gitconfig 和 git-credential-helper 有什么区别?

javascript - Nodegit 克隆不起作用?

linux - Grep csv 与来自另一个 csv 的参数

c++ - 使用 Xcode 5 为 Unity 4 创建桌面插件

git - 从 github 的 master 中删除文件

Xcode-错误 : pathspec '...' did not match any file(s) known to git

linux - 从 shell 脚本中的另一个变量创建一个变量

linux - Linux 中的输出格式