簡體   English   中英

Git:在Rebase期間阻止提交

[英]Git: Preventing Commit During a 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中間。

您可以將以下本地預提交掛鈎添加為.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或只輸入或者什么更方便,腳本/提交將停止。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM