Coo*_*ham 6 git macos bash 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
Run Code Online (Sandbox Code Playgroud)
我可以轻松修复损坏的结果状态。我只是想弄清楚是否有一种方法可以配置一些东西来防止我在 rebase 过程中执行 5in Correct 命令。
小智 6
您可以添加以下本地预提交挂钩.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
Run Code Online (Sandbox Code Playgroud)
然后就可以chmod +x .git/hooks/pre-commit了。如果正在进行变基,那么系统会提示您继续,或者按 ctrl-c 或只是输入或对您来说更方便的命令,并且脚本/提交将停止。
| 归档时间: |
|
| 查看次数: |
804 次 |
| 最近记录: |