diff --git a/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike b/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike
index 33ed7b2414fd41940fcfe7709a2526cd3b78b3b6..3a855e6121ba94a231230ba79a77895495e11145 100644
--- a/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike
+++ b/lib/modules/Tools.pmod/Standalone.pmod/git_export_autodoc.pike
@@ -480,11 +480,15 @@ void export_autodoc_for_ref(string ref)
 
     if (sizeof(doc_parents) > 1) {
       // Check if all of the parents are needed.
-      // NB: We only check direct parents, but this should
+      // NB: We only check parents and grandparents, but this should
       //     be sufficient in most circumstances.
       foreach(doc_parents, string parent) {
 	if (doc_to_parents[parent]) {
 	  doc_parents -= (array)doc_to_parents[parent];
+	  foreach((array)doc_to_parents[parent], string grandparent) {
+	    if (doc_to_parents[grandparent])
+	      doc_parents -= (array)doc_to_parents[grandparent];
+	  }
 	}
       }
     }