diff --git a/src/jamidht/conversationrepository.cpp b/src/jamidht/conversationrepository.cpp
index 40dbc19294df2be0855adc5330cd37d0d6ef8672..8112003aa0a9cfc5b314d3b8232d8e7d478cc972 100644
--- a/src/jamidht/conversationrepository.cpp
+++ b/src/jamidht/conversationrepository.cpp
@@ -835,12 +835,13 @@ ConversationRepository::Impl::createMergeCommit(git_index* index, const std::str
 
     // Commit
     git_buf to_sign = {};
-    // Check if the libgit2 library version is 1.8.0 or higher
-#if( LIBGIT2_VER_MAJOR > 1 ) || ( LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR >= 8 )
-    // For libgit2 version 1.8.0 and above
+    // The last argument of git_commit_create_buffer is of type
+    // 'const git_commit **' in all versions of libgit2 except 1.8.0,
+    // 1.8.1 and 1.8.3, in which it is of type 'git_commit *const *'.
+#if LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR == 8 && \
+    (LIBGIT2_VER_REVISION == 0 || LIBGIT2_VER_REVISION == 1 || LIBGIT2_VER_REVISION == 3)
     git_commit* const parents_ptr[2] {parents[0].get(), parents[1].get()};
 #else
-    // For libgit2 versions older than 1.8.0
     const git_commit* parents_ptr[2] {parents[0].get(), parents[1].get()};
 #endif
     if (git_commit_create_buffer(&to_sign,
@@ -1929,9 +1930,11 @@ ConversationRepository::Impl::commit(const std::string& msg, bool verifyDevice)
     GitCommit head_commit {head_ptr, git_commit_free};
 
     git_buf to_sign = {};
-    // Check if the libgit2 library version is 1.8.0 or higher
-#if( LIBGIT2_VER_MAJOR > 1 ) || ( LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR >= 8 )
-    // For libgit2 version 1.8.0 and above
+    // The last argument of git_commit_create_buffer is of type
+    // 'const git_commit **' in all versions of libgit2 except 1.8.0,
+    // 1.8.1 and 1.8.3, in which it is of type 'git_commit *const *'.
+#if LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR == 8 && \
+    (LIBGIT2_VER_REVISION == 0 || LIBGIT2_VER_REVISION == 1 || LIBGIT2_VER_REVISION == 3)
     git_commit* const head_ref[1] = {head_commit.get()};
 #else
     const git_commit* head_ref[1] = {head_commit.get()};