Re: [PATCH] git-filter-branch: Add an example on how to remove empty commits
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Oct 30, 2008, 00:56 UTC
- Message-ID
- <alpine.DEB.1.00.0810300151480.22125@pacific.mpi-cbg.de.mpi-cbg.de>
- In-Reply-To
- <1225326833-15210-1-git-send-email-pasky@suse.cz>
Hi,
On Wed, 29 Oct 2008, Petr Baudis wrote:
Show 12 quoted lines
> +To remove commits that are empty (do not introduce any change): > + > +------------------------------------------------------------------------------ > +git rev-list HEAD | while read c; do [ -n "$(git diff-tree --root $c)" ] || echo $c; done > revs > + > +git filter-branch --commit-filter ' > + if grep -q "$GIT_COMMIT" '"$(pwd)/"revs'; > + then > + skip_commit "$@"; > + else > + git commit-tree "$@"; > + fi' HEAD
You would not need to use the temporary "revs" file by using something (totally untested, of course):
git filter-branch --commit-filter '
if git diff-tree --exit-status -q "$GIT_COMMIT";
then
git commit-tree "$@";
else
skip_commit "$@";
fi' HEADOf course, you could also mention that you could use
git log --cherry-pick -p --pretty=format: ..<branch>@{1}to verify that all skipped commits had empty diffs. That one is also totally untested.
Ciao, Dscho