diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index 22de2450f2..1835e47318 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -47,6 +47,10 @@ func renderIssueLinks(oldCommits *list.List, repoLink string) *list.List {
 // Commits render branch's commits
 func Commits(ctx *context.Context) {
 	ctx.Data["PageIsCommits"] = true
+	if ctx.Repo.Commit == nil {
+		ctx.Handle(404, "Commit not found", nil)
+		return
+	}
 
 	commitsCount, err := ctx.Repo.Commit.CommitsCount()
 	if err != nil {