diff --git a/modules/git/command.go b/modules/git/command.go
index 127e95ecfb..d83c42fdc2 100644
--- a/modules/git/command.go
+++ b/modules/git/command.go
@@ -199,7 +199,11 @@ func (c *Command) RunInDirTimeoutEnv(env []string, timeout time.Duration, dir st
 		return nil, ConcatenateError(err, stderr.String())
 	}
 	if stdout.Len() > 0 && log.IsTrace() {
-		log.Trace("Stdout:\n %s", stdout.Bytes()[:1024])
+		tracelen := stdout.Len()
+		if tracelen > 1024 {
+			tracelen = 1024
+		}
+		log.Trace("Stdout:\n %s", stdout.Bytes()[:tracelen])
 	}
 	return stdout.Bytes(), nil
 }