【问题标题】:Deeply rename a variable inside a large PR stack在大型 PR 堆栈中深度重命名变量
【发布时间】:2022-10-05 10:17:54
【问题描述】:

我有一个 100 次提交的 PR,它将作为一些较小的 PR 提交。

在 PR 堆栈的底部,我选择了一个我现在觉得很奇怪的变量名,并且想在每次提交期间更改它,但不想在任何地方繁琐地解决合并冲突。

有没有办法自动化这个,使用一些cli命令来搜索+替换变量名?

【问题讨论】:

    标签: git-rebase


    【解决方案1】:

    首先,避免 rebase 中的合并冲突:

    git rebase --strategy recursive --strategy-option theirs <base-commit-ish>

    然后,在每个pick 之后,运行下面的exec

    pick 271c87512 Rename Foo -> Bar

    pick 2dd206e33 Utilize Bar

    exec MSG=$(git log -1 --format=%B HEAD); git undo; git reset; ag -0 -l 'Foo' | xargs -0 sed -ri.bak -e 's/Foo/Bar/g'; git clean -f '**/*.bak'; git add .; yarn prettier $(git diff --diff-filter=d --staged --name-only) && git add . && git commit -m "$MSG" --no-verify

    你也可以在命令行上传递这个exec 命令,但是, 我很满意只是复制/粘贴到git-rebase-todo

    ag 命令是 the_silver_searcher, brew install the_silver_searcher

    【讨论】:

      猜你喜欢
      • 2017-07-11
      • 2022-10-07
      • 1970-01-01
      • 2020-07-06
      • 2012-01-09
      • 1970-01-01
      • 2021-11-21
      • 2021-12-04
      相关资源
      最近更新 更多