diff --git a/pagure/lib/git.py b/pagure/lib/git.py
index 8b7e080..5702b79 100644
--- a/pagure/lib/git.py
+++ b/pagure/lib/git.py
@@ -89,6 +89,9 @@ def commit_to_patch(
             # First commit in the repo
             diff = commit.tree.diff_to_tree(swap=True)
 
+        if diff.patch is None:
+            continue
+
         if find_similar and diff:
             diff.find_similar()
 
@@ -138,7 +141,7 @@ Subject: {subject}
     if separated:
         return patch
     else:
-        return "".join(patch)
+        return "".join(filter(None, patch))
 
 
 def generate_gitolite_acls(project=None, group=None):
diff --git a/tests/test_pagure_lib_git.py b/tests/test_pagure_lib_git.py
index 8ebd25c..f305602 100644
--- a/tests/test_pagure_lib_git.py
+++ b/tests/test_pagure_lib_git.py
@@ -3277,6 +3277,20 @@ class PagureLibGitCommitToPatchtests(tests.Modeltests):
 
         self.second_commit = repo.revparse_single("HEAD")
 
+        # Add empty commit
+        repo.create_commit(
+            "refs/heads/master",  # the name of the reference to update
+            author,
+            committer,
+            "Empty commit",
+            # binary string representing the tree object ID
+            tree,
+            # list of binary strings representing parents of the new commit
+            [self.second_commit.oid.hex],
+        )
+
+        self.third_commit = repo.revparse_single("HEAD")
+
     def test_commit_to_patch_first_commit(self):
         """ Test the commit_to_patch function of pagure.lib.git. """
         repo = pygit2.init_repository(self.gitrepo)
@@ -3622,6 +3636,24 @@ index 9f44358..2a552bb 100644
 
         self.assertEqual(output, exp)
 
+    def test_commit_to_patch_empty_commit(self):
+        """ Test the commit_to_path function of pagure.lib.git. """
+        repo = pygit2.init_repository(self.gitrepo)
+
+        patch = pagure.lib.git.commit_to_patch(repo, self.third_commit)
+        exp = ""
+        self.assertEqual(patch, exp)
+
+    def test_commit_to_patch_empty_commit_diff(self):
+        """ Test the commit_to_patch function of pagure.lib.git. """
+        repo = pygit2.init_repository(self.gitrepo)
+
+        patch = pagure.lib.git.commit_to_patch(
+            repo, self.third_commit, diff_view=True
+        )
+        exp = ""
+        self.assertEqual(patch, exp)
+
 
 if __name__ == "__main__":
     unittest.main(verbosity=2)