2011-11-22 60 views
2

我一直在使用這種混帳別名這是我從一個問題了就在這裏:Git的別名壁球都與特定的承諾提交信息

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

所以現在我有一系列的n承諾,順序地,它們都包含作爲提交消息的「wip」。

我該如何讓git別名去尋找合適數量的提交備份包含「wip」的樹並將其壓扁?它實際上可能嗎?

+1

如果你有'fixup!'而不是'wip',你可以試試'git rebase --interactive --autosquash'(http://stackoverflow.com/questions/2302736/trimming-git-checkins-squashing -git歷史/ 2302947#2302947) – VonC

回答

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--amend從原始的別名改變。