我一直在使用这个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”的正确数量的提交并将它们压扁?它真的可能吗?
答案 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}}。