例如,我不想硬编码字符串
"load_more"
所以我要重做/调整这些提交:
git rebase --exec 'git difflastcommitadded | ag load_more && { echo "found load_more"; git redo; } || echo "ok"' --no-reschedule-failed-exec -i 315abbd5b
设置:
-
安装
ag
(
brew install the_silver_searcher
)(grep/ack替代方案)
-
添加此数字
difflastcommitadded
别名:
git config --global --edit
brew install the_silver_searcher
粘贴:
[alias]
# From: https://stackoverflow.com/questions/73981158/git-rebase-make-bad-name-in-large-pr-stack-disappear/73981159#73981159
difflastcommitadded = !git diff HEAD^..HEAD --no-ext-diff --unified=0 --exit-code -a --no-prefix | egrep '^\\+'
或者,如果你想从回购中的文件夹中完全废除变量名,请继续阅读这个不太灵活的例子:
git rebase --exec 'ag -0 -l AccountNode ui/app && git redo || echo "ok"' -i 315abbd5b
这将重新设置基准,但只要出现引入的提交,就会停止
AccountNode
在ui/app文件夹中,撤消提交,并将这些更改弹出到您的工作目录中,这样您就可以在ide中修复它。
一旦修复了的实例
AccountNode
您可以使用以下脚本进行良好的安全检查:
ag -0 -l AccountNode ui/app/pages/AccountManagement2 && echo "still contains AccountNode" || {
yarn --cwd ui run jest -i && git add . && git commit && git rebase --continue
}
在我的例子中,
git commit
运行更漂亮的+esint,但不运行测试(现在在ci中运行的测试)
这取决于
git redo
此处提到的别名:
git rebase - pop each commit into working dir to easily edit, re-use commit msg