duandi8544 2015-01-02 06:59
浏览 115
已采纳

在运行go fmt每个提交时,是否有任何工具可以在Git中重新建立分支的基础?

I wish to rebuild/rebase all commits in a Git branch X using a source code formatting tool like go fmt or indent.

I'd expect the workflow to roughly consist of making a new branch off master and iterating the following with $_ ranging over the commits in X:

git cherry-pick $_
go fmt ...
git commit -a --amend

Or maybe even

git cherry-pick -n $_
go fmt ...
git cherry-pick --continue

I wouldn't expect -n and --continue to play together like that, though. Also, one should naturally do a go fmt commit to X and go diff X new when done.

However, there are many steps that can go wrong with this procedure, like the -a seeking to change files that weren't changed in the original commit, go fmt confusing Git's patching, Git changing the commit dates, etc.

None of that is particularly troublesome, but if a quick tool or simpler workflow does this more cleanly, then I'd love to know about it.

  • 写回答

1条回答 默认 最新

  • drs7798 2015-01-02 15:56
    关注

    but if a quick tool or simpler workflow does this more cleanly, then I'd love to know about it.

    As Joseph K. Strauss mentions in the comments, git filter-branch should be enough, plus go fmt using the three dot notation:

    git filter-branch --tree-filter 'go fmt ...'
    

    You can read (much) more on filter-branch at "git filter-branch - discard the changes to a set of files in a range of commits".

    That command will run against all local branch, and will change the history (since new SHA1 will be generated for each modified commit).
    A git push --force might be needed to publish the new history to its upstream repo: do warn the other collaborators, for them to reset their local repos.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测