diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index f704492fe..850ff4969 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -806,8 +806,12 @@ public class RebaseCommand extends GitCommand { if (!line.trim().startsWith("#")) //$NON-NLS-1$ result.append(line).append("\n"); //$NON-NLS-1$ } - if (!commitMessage.endsWith("\n")) //$NON-NLS-1$ - result.deleteCharAt(result.length() - 1); + if (!commitMessage.endsWith("\n")) { //$NON-NLS-1$ + int bufferSize = result.length(); + if (bufferSize > 0 && result.charAt(bufferSize - 1) == '\n') { + result.deleteCharAt(bufferSize - 1); + } + } return result.toString(); }