gpt4 book ai didi

git:自动修复已更改行所属的提交

转载 作者:行者123 更新时间:2023-12-03 17:35:28 25 4
gpt4 key购买 nike

想象一下在评论中打错字或类似的东西:

- // Do thigns
+ // Do things

现在,通过做 git blame @ -- file您会看到最初添加该行的提交:
decafbad ... // Do thigns

您可以通过运行以下命令手动修复该行: git commit --fixup decafbad .

有什么办法可以自动化这个 git blame @ -- file |grep thigns , git commit --fixup decafbad循环?

最佳答案

bash我写了一个小脚本来获得它。此脚本假设您只进行了一次修复更改,因此它只查看修改后的第一个文件和更改的第一行:

file=$(git diff | sed -n "s/.* a\/\(.*\) \+\+\+.*/\1/p")
line_removed=$(git diff | tail -n +6 | sed -n "s/^-\(.*\)/\1/p")
hash=$(git blame HEAD $file | grep $line_removed | awk "{print \$1}")
git commit -a --fixup $hash

如果你把这个代码放在 /usr/bin/git-auto-fixup 里面(并使其可执行),然后您可以像这样调用它: git auto-fixup

关于git:自动修复已更改行所属的提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44081376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com