2

I've been using this git-alias which I got from a question on here:

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

So now I have a series of n commits, sequentially, which all contain 'wip' on its own as the commit message.

How do I make a git alias to go about finding the right number of commits back up the tree which contain "wip" and squashes them? Is it actually possible?

bcmcfc
  • 25,966
  • 29
  • 109
  • 181
  • 1
    If you had `fixup!` instead of `wip`, you might try a `git rebase --interactive --autosquash` (http://stackoverflow.com/questions/2302736/trimming-git-checkins-squashing-git-history/2302947#2302947) – VonC Nov 22 '11 at 14:03

1 Answers1

1

You will probably need to interactively rebase and squash the existing wip commits. Since a rebase with squashes will change history, it makes it difficult (though not impossible) to automate; it's best to rebase on a case-by-case basis. After doing this, you can change your wip alias to the following:

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'

This would avoid contiguous wip commits in your history. The alias is changed from your original alias by using the xargs -r option so that If the standard input is completely empty, do not run the command. and if the current HEAD commit subject is wip, use commit's --amend.

Go Dan
  • 15,194
  • 6
  • 41
  • 65