Git通过在每次提交时运行外部工具来重写历史记录

时间:2018-02-13 09:01:33

标签: c# git

我们有一个包含数千个提交的repo,它们使用了我们想用默认的Microsoft代码替换的非常旧的代码约定。最简单的方法是仅在最新提交时运行代码格式化工具,但这样我们就会失去"责备"并且历史越来越难以遵循。 这可以通过在每次提交时运行代码格式化工具(在我们的案例中为https://github.com/dotnet/codeformatter)来实现,从而保留更改历史记录,以及我们应该使用哪种版本的filter-branch?

编辑:结果我正要使用的工具在某些提交中崩溃,这就是为什么filter-branch对我不起作用并且没有对提交应用任何更改

2 个答案:

答案 0 :(得分:3)

您可以使用树过滤器执行此操作:

git filter-branch --tree-filter "CodeFormatter.exe"

答案 1 :(得分:1)

SELECT @Param1 = magic1.ID ,
       @Param2 = magic2.ID ,
       @Param3 = magic3.ID ,
       @Param4 = magic4.ID ,
       @Param5 = magic5.ID ,
       @Param6 = magic6.ID ,
       @Param7 = magic7.ID ,
       @Param8 = magic8.ID ,
       @Param9 = magic9.ID ,
       @Param10 = magic10.ID,
       @ParamNum = items0.MagParamNum,
       @ID64 = items0.ID64
FROM SRO_VT_SHARD.dbo._Inventory AS invent0
INNER JOIN SRO_VT_SHARD.dbo._Items AS items0 ON invent0.ItemID = items0.ID64 AND (invent0.Slot = 13)
INNER JOIN SRO_VT_SHARD.dbo._RefObjCommon AS ref0 ON items0.RefItemID = ref0.ID
INNER JOIN SRO_VT_SHARD.dbo._Char AS chart ON invent0.CharID = chart.CharID
LEFT JOIN _RefMagicOptNew AS magic1 ON (items0.MagParam1 & 2147483647) = magic1.ID
LEFT JOIN _RefMagicOptNew AS magic2 ON (items0.MagParam2 & 2147483647) = magic2.ID
LEFT JOIN _RefMagicOptNew AS magic3 ON (items0.MagParam3 & 2147483647) = magic3.ID
LEFT JOIN _RefMagicOptNew AS magic4 ON (items0.MagParam4 & 2147483647) = magic4.ID
LEFT JOIN _RefMagicOptNew AS magic5 ON (items0.MagParam5 & 2147483647) = magic5.ID
LEFT JOIN _RefMagicOptNew AS magic6 ON (items0.MagParam6 & 2147483647) = magic6.ID
LEFT JOIN _RefMagicOptNew AS magic7 ON (items0.MagParam7 & 2147483647) = magic7.ID
LEFT JOIN _RefMagicOptNew AS magic8 ON (items0.MagParam8 & 2147483647) = magic8.ID
LEFT JOIN _RefMagicOptNew AS magic9 ON (items0.MagParam9 & 2147483647) = magic9.ID
LEFT JOIN _RefMagicOptNew AS magic10 ON (items0.MagParam10 & 2147483647) = magic10.ID
LEFT JOIN _RefMagicOptNew AS magic11 ON (items0.MagParam11 & 2147483647) = magic11.ID
LEFT JOIN _RefMagicOptNew AS magic12 ON (items0.MagParam12 & 2147483647) = magic12.ID
WHERE chart.CharID = @CharID

即。执行交互式rebase executing the given command on every commit

将命令缩短为

git rebase --interactive --exec CodeFormatter.exe --root