1

I need to extract a snippet of code in app/views/cgi_testing_seeds/index.html.haml, form this commit '77df270', because it should be owned by other commit.

It's very complicated to revert or rollback to that commit '77df270', Then redo all the remaining commits again,

For example If I only want to revert the code of index method in the CgiTestingSeedsController.rb,

And add it into the commit 4b733c5 , how to ?

Or extract the code of the method and keep it in staged status, how to ?

What's an easier to do this in Git.

Brief log

4b733c5 - (HEAD, feature/testing_seeds_model) Scaffold:Testing seed and generate testing data via 'faker gem' (7 minutes ago) <poc7667>
2fd8204 - (develop) Merge branch 'hotfix/wrong_column_names_in_CGIparamters' into develop (4 days ago) <poc7667>
052e2ff - Remove 'name' in 'cgi_attributes' and fix wrong name for 'default_value' (4 days ago) <poc7667>
77df270 - Scaffold: CgiTestingSeed (2 days ago) <poc7667>

Changed file in the commit 77df270

77df270 - Scaffold: CgiTestingSeed (2 days ago) <poc7667>
app/assets/javascripts/cgi_testing_seeds.js.coffee
app/controllers/cgi_testing_seeds_controller.rb
app/helpers/cgi_testing_seeds_helper.rb

CgiTestingSeedsController.rb in the commit 77df270

class CgiTestingSeedsController < ApplicationController
  before_action :set_cgi_testing_seed, only: [:show, :edit, :update, :destroy]

  # GET /cgi_testing_seeds
  # GET /cgi_testing_seeds.json
  def index
    @cgi_testing_seeds = CgiTestingSeed.all
  end

  # GET /cgi_testing_seeds/1
  # GET /cgi_testing_seeds/1.json
  def show
  end
newBike
  • 14,385
  • 29
  • 109
  • 192

1 Answers1

1

For example If I only want to revert the code of index method in the CgiTestingSeedsController.rb,

You could consider making a patch, using git diff:

git diff 77df270 77df270~ > revert.diff
vi revert.diff # leave only changes regarding the `index` method 

Note the order 77df270 77df270~: a diff from what you changed (77df270) to what you had before the changes: 77df270~: this is done to revert the changes in 77df270.

And add it into the commit 4b733c5 , how to ?

You can apply your diff patch file using git apply (as in here):

git apply revert.diff

Since it doesn't create a commit, you can then use git commit --amend to modify your current latest commit.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250