我的作業流程通常涉及上傳提交以供審查,例如提交鏈A(HEAD) -> B -> C- 如果我在提交時獲得審查B- 我運行git rebase -i,選擇B進行編輯,然后運行,然后git commit --amend在git rebase --continue鏈中就地修復提交來修補提交。
這是常見的流程,但有時 - 當我編輯時,B我會在A.
互動式 rebase 作業流程應該作業的方式是我解決沖突,使用git add- 暫存它們,然后在git rebase --continue 不修改 commit 的情況下運行。
然而,無合并沖突的git commit --amend流程是如此普遍,以至于我經常發現自己犯了一個心不在焉的錯誤,即運行git commit --amend; git rebase --continue而不是git rebase --continue- 這對我的鏈造成嚴重破壞,將兩個提交壓縮在一起,然后我需要深入研究git reflog以取消壓縮它們。
這幾乎從來都不是所期望的行為,而且通常是一個錯誤——很少有人想要修改一個新的提交,并將已解決的合并沖突修改為之前的提交。
有沒有辦法配置 git 在合并沖突中禁止修改提交?
uj5u.com熱心網友回復:
在變基期間,有一個.git/rebase-merge目錄。--amend可以在鉤子prepare-commit-msg中捕獲。
或提交,后跟提交物件名稱(如果給出了 -c、-C 或 --amend 選項)。
因此,其中一個想法是失敗prepare-commit-msg并中止提交(如果.git/rebase-merge存在并--amend使用)。為了繞過測驗,我們可以定義一個配置值,foo.bar.
Bash 中的演示,
#!/bin/bash
msg_file=$1
msg_source=$2
msg_object=$3
foo_bar=$(git config --get foo.bar)
if [[ "${foo_bar}" != "false" ]];then
gitdir=$(git rev-parse --absolute-git-dir)
rebase_dir=${gitdir}/rebase-merge
if [[ -d "${rebase_dir}" ]] && [[ "$msg_source" = commit ]];then
echo "Forbid 'git commit --amend' during rebase"
echo "Maybe you want 'git rebase --continue'?"
echo "If you do want to amend during rebase, use 'git -c foo.bar=false commit --amend'"
exit 1
fi
fi
副作用是git commit -C $commit或者git commit -c $commit在 rebase 期間也失敗了。但是我們可以用-c foo.bar=false.
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/498417.html
標籤:混帐
