diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index 79e6ae26aad674de76dd5b6af7d99853547406e2..d6bcb852a4655c84dc829d63a7be75b442b39e88 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -10,6 +10,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
   before_action :define_show_vars, only: [:show, :diffs, :commits, :builds]
   before_action :define_widget_vars, only: [:merge, :cancel_merge_when_build_succeeds, :merge_check]
   before_action :ensure_ref_fetched, only: [:show, :diffs, :commits, :builds]
+  before_action :check_target_branch_exists, only: [:revert]
 
   # Allow read any merge_request
   before_action :authorize_read_merge_request!
@@ -277,6 +278,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
     return render_404 unless @project.merge_requests_enabled
   end
 
+  def check_target_branch_exists
+    return render_404 unless @merge_request.target_branch_exists?
+  end
+
   def validates_merge_request
     # If source project was removed (Ex. mr from fork to origin)
     return invalid_mr unless @merge_request.source_project