使用特定提交消息压缩所有提交的Git别名

时间:2011-11-22 11:48:54

标签: git alias

我一直在使用这个git-alias,我在这里提出了一个问题:

wip = !f() { git add -A; git ls-files --deleted -z | xargs -0 git rm; git commit -m "wip";}; f

所以现在我有一系列n次提交,顺序,它们都包含'wip'作为提交消息。

如何创建一个git别名,以便在树中找到包含“wip”的正确数量的提交并将它们压扁?它真的可能吗?

1 个答案:

答案 0 :(得分:1)

您可能需要以交互方式rebase和压缩现有的wip提交。由于带有南瓜的rebase会改变历史,因此自动化很难(尽管不是不可能);最好rebase根据具体情况。完成此操作后,您可以将wip别名更改为以下内容:

git config --global alias.wip '!f() { git add -A; git ls-files --deleted -z | xargs -0 -r git rm; s=`git show --format=%s HEAD | head -1`; if [ "wip" = "$s" ]; then git commit --amend -m "wip"; else git commit -m "wip"; fi;}; f'

这样可以避免历史记录中连续wip次提交。使用xargs -r option更改别名与原始别名,以便If the standard input is completely empty, do not run the command.如果当前HEAD提交主题为wip,请使用commit的{ {1}}。