[PATCH] git-filter-branch: Add an example on how to remove empty commits
From: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Petr Baudis <pasky@suse.cz>
---
Documentation/git-filter-branch.txt | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
index fed6de6..2565244 100644
--- a/Documentation/git-filter-branch.txt
+++ b/Documentation/git-filter-branch.txt
@@ -246,6 +246,21 @@ git filter-branch --commit-filter '
fi' HEAD
------------------------------------------------------------------------------
+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
+
+------------------------------------------------------------------------------
+
The function 'skip_commit' is defined as follows:
--------------------------
--
1.5.6.3.536.g61aad