Git:在重新启动期间阻止提交

时间:2017-02-27 17:37:20

标签: 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

我可以轻松修复破碎的结果状态。我只想弄清楚是否有一种方法可以配置一些东西以防止我在能够执行5incorrect命令时如果我在一个rebase中间。

1 个答案:

答案 0 :(得分:2)

您可以将以下本地预提交挂钩添加为.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或只输入或者为您提供的便利,脚本/提交将停止。

相关问题