diff --git a/app/assets/stylesheets/sections/commits.scss b/app/assets/stylesheets/sections/commits.scss
index ff293bc4a0063e8d213686567d10e8e44cda4502..ef3f1b06c588098535209cdbd7a6ebce51722d51 100644
--- a/app/assets/stylesheets/sections/commits.scss
+++ b/app/assets/stylesheets/sections/commits.scss
@@ -27,10 +27,14 @@
       line-height: 2;
     }
 
-    .view-file {
-      font-weight: bold;
+    .diff-btn-group {
       float: right;
-      background-color: #EEE;
+
+      .btn {
+        background-color: #EEE;
+        color: #666;
+        font-weight: bolder;
+      }
     }
 
     .commit-short-id {
diff --git a/app/controllers/projects/edit_tree_controller.rb b/app/controllers/projects/edit_tree_controller.rb
index 6bd1a455f323a876e6a9e35d97139bfdf1542291..c54b757d13cba9cdd1bcaf85846cb7e1e556de9b 100644
--- a/app/controllers/projects/edit_tree_controller.rb
+++ b/app/controllers/projects/edit_tree_controller.rb
@@ -12,7 +12,16 @@ class Projects::EditTreeController < Projects::BaseTreeController
 
     if result[:status] == :success
       flash[:notice] = "Your changes have been successfully committed"
-      redirect_to project_blob_path(@project, @id)
+
+      # If blob edit was initiated from merge request page
+      from_merge_request = MergeRequest.find_by(id: params[:from_merge_request_id])
+
+      if from_merge_request
+        from_merge_request.reload_code
+        redirect_to diffs_project_merge_request_path(from_merge_request.target_project, from_merge_request)
+      else
+        redirect_to project_blob_path(@project, @id)
+      end
     else
       flash[:alert] = result[:error]
       render :show
diff --git a/app/views/projects/commits/_diffs.html.haml b/app/views/projects/commits/_diffs.html.haml
index a41a89bb9724fc501489c18eacfa3191796cb894..0fd04f32ba8a15a53fba5586e0e94f14ea12d6d0 100644
--- a/app/views/projects/commits/_diffs.html.haml
+++ b/app/views/projects/commits/_diffs.html.haml
@@ -49,18 +49,26 @@
           - if diff.deleted_file
             %span= diff.old_path
 
-            - if @commit.parent_ids.present?
-              = link_to project_blob_path(project, tree_join(@commit.parent_id, diff.new_path)), { class: 'btn btn-small view-file' } do
-                View file @
-                %span.commit-short-id= @commit.short_id(6)
+            .diff-btn-group
+              - if @commit.parent_ids.present?
+                = link_to project_blob_path(project, tree_join(@commit.parent_id, diff.new_path)), { class: 'btn btn-small view-file' } do
+                  View file @
+                  %span.commit-short-id= @commit.short_id(6)
           - else
             %span= diff.new_path
             - if diff.a_mode && diff.b_mode && diff.a_mode != diff.b_mode
               %span.file-mode= "#{diff.a_mode} → #{diff.b_mode}"
 
-            = link_to project_blob_path(project, tree_join(@commit.id, diff.new_path)), { class: 'btn btn-small view-file' } do
-              View file @
-              %span.commit-short-id= @commit.short_id(6)
+            .diff-btn-group
+              - if @merge_request && @merge_request.source_project
+                = link_to project_edit_tree_path(@merge_request.source_project, tree_join(@merge_request.source_branch, diff.new_path), from_merge_request_id: @merge_request.id), { class: 'btn btn-small' } do
+                  Edit
+                &nbsp;
+
+              = link_to project_blob_path(project, tree_join(@commit.id, diff.new_path)), { class: 'btn btn-small view-file' } do
+                View file @
+                %span.commit-short-id= @commit.short_id(6)
+
 
         .content
           -# Skipp all non non-supported blobs
diff --git a/app/views/projects/edit_tree/show.html.haml b/app/views/projects/edit_tree/show.html.haml
index 433131640a19149d9162bb03064597e715494799..96c00ab3661470e73228b6260369dfd7749ec798 100644
--- a/app/views/projects/edit_tree/show.html.haml
+++ b/app/views/projects/edit_tree/show.html.haml
@@ -23,6 +23,7 @@
     .form-actions
       = hidden_field_tag 'last_commit', @last_commit
       = hidden_field_tag 'content', '', id: "file-content"
+      = hidden_field_tag 'from_merge_request_id', params[:from_merge_request_id]
       .commit-button-annotation
         = button_tag "Commit changes", class: 'btn commit-btn js-commit-button btn-primary'
         .message