diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb
index 791ed88db30faee34999024814cb12ab7c42103e..bfc59bcc8629d89257d13e2290b47227ef0ff5ca 100644
--- a/app/controllers/projects/commit_controller.rb
+++ b/app/controllers/projects/commit_controller.rb
@@ -12,7 +12,6 @@ class Projects::CommitController < Projects::ApplicationController
   before_action :authorize_read_pipeline!, only: [:pipelines]
   before_action :commit
   before_action :define_commit_vars, only: [:show, :diff_for_path, :pipelines]
-  before_action :define_status_vars, only: [:show, :pipelines]
   before_action :define_note_vars, only: [:show, :diff_for_path]
   before_action :authorize_edit_tree!, only: [:revert, :cherry_pick]
 
@@ -106,10 +105,6 @@ class Projects::CommitController < Projects::ApplicationController
     }
   end
 
-  def define_status_vars
-    @ci_pipelines = project.pipelines.where(sha: commit.sha)
-  end
-
   def assign_change_commit_vars(mr_source_branch)
     @commit = project.commit(params[:id])
     @target_branch = params[:target_branch]
diff --git a/app/views/projects/commit/_ci_menu.html.haml b/app/views/projects/commit/_ci_menu.html.haml
index 13ab2253733e402cb01084d3005fb50c3b1347ba..8aed88da38babd417f88496e1e124f097ade9aa2 100644
--- a/app/views/projects/commit/_ci_menu.html.haml
+++ b/app/views/projects/commit/_ci_menu.html.haml
@@ -7,4 +7,4 @@
     = nav_link(path: 'commit#pipelines') do
       = link_to pipelines_namespace_project_commit_path(@project.namespace, @project, @commit.id) do
         Pipelines
-        %span.badge= @ci_pipelines.count
+        %span.badge= @commit.pipelines.size
diff --git a/app/views/projects/commit/pipelines.html.haml b/app/views/projects/commit/pipelines.html.haml
index 8233e26e4e73794991e4bdd58e24d8332f35f498..00e7cdd17297d19226aeae58103156c161db0282 100644
--- a/app/views/projects/commit/pipelines.html.haml
+++ b/app/views/projects/commit/pipelines.html.haml
@@ -3,4 +3,4 @@
 = render "commit_box"
 
 = render "ci_menu"
-= render "pipelines_list", pipelines: @ci_pipelines
+= render "pipelines_list", pipelines: @commit.pipelines.order(id: :desc)
diff --git a/changelogs/unreleased/26117-sort-pipeline-for-commit.yml b/changelogs/unreleased/26117-sort-pipeline-for-commit.yml
new file mode 100644
index 0000000000000000000000000000000000000000..b2f5294d380f56662c2832d5269de47e08835afd
--- /dev/null
+++ b/changelogs/unreleased/26117-sort-pipeline-for-commit.yml
@@ -0,0 +1,4 @@
+---
+title: Add sorting pipeline for a commit
+merge_request: 8319
+author: Takuya Noguchi
diff --git a/spec/controllers/projects/commit_controller_spec.rb b/spec/controllers/projects/commit_controller_spec.rb
index 646b097d74e0fba6bca594b1c7c63de5f6282c2e..0fa06a38d2a02b3fc2f0e3c60d22ef33aa8a8a04 100644
--- a/spec/controllers/projects/commit_controller_spec.rb
+++ b/spec/controllers/projects/commit_controller_spec.rb
@@ -1,9 +1,10 @@
 require 'spec_helper'
 
 describe Projects::CommitController do
-  let(:project) { create(:project) }
-  let(:user)    { create(:user) }
-  let(:commit)  { project.commit("master") }
+  let(:project)  { create(:project) }
+  let(:user)     { create(:user) }
+  let(:commit)   { project.commit("master") }
+  let(:pipeline) { create(:ci_pipeline, project: project, commit: commit) }
   let(:master_pickable_sha) { '7d3b0f7cff5f37573aea97cebfd5692ea1689924' }
   let(:master_pickable_commit)  { project.commit(master_pickable_sha) }
 
@@ -309,4 +310,35 @@ describe Projects::CommitController do
       end
     end
   end
+
+  describe 'GET pipelines' do
+    def get_pipelines(extra_params = {})
+      params = {
+        namespace_id: project.namespace.to_param,
+        project_id: project.to_param
+      }
+
+      get :pipelines, params.merge(extra_params)
+    end
+
+    context 'when the commit exists' do
+      context 'when the commit has one or more pipelines' do
+        it 'shows pipelines' do
+          get_pipelines(id: commit.id)
+
+          expect(response).to be_ok
+        end
+      end
+    end
+
+    context 'when the commit does not exist' do
+      before do
+        get_pipelines(id: 'e7a412c8da9f6d0081a633a4a402dde1c4694ebd')
+      end
+
+      it 'returns a 404' do
+        expect(response).to have_http_status(404)
+      end
+    end
+  end
 end