1

I did a git add, git commit, and git push for 9 files (2 of those being Gemfile and Gemfile.lock). My team has informed me that we do not need Gemfile and gemfile.lock in the code review. What is the easiest way to revert these 2 files? (I would like to keep the other 7). I pushed these changes to my branch, can I ignore them when I am merging to master? Or should I somehow revert the changes to the 2 files (Gemfile and gemfile.lock)?

lakeIn231
  • 1,177
  • 3
  • 14
  • 34

1 Answers1

3

The simplest thing is to reset Gemfile and Gemfile.lock to their present state on master.

You can do this in two ways; either by adding a new commit which discards your changes to those files, or by amending whichever commit introduced those changes.

The former is the simplest. Add a new commit on your branch which discards the changes you made to Gemfile and Gemfile.lock:

  1. Check out your branch, in its current state, with Gemfile and Gemfile.lock
  2. Check out master's version of Gemfile and Gemfile.lock:

    $ git checkout master -- Gemfile Gemfile.lock
    
  3. Add and commit your changes

    $ git add Gemfile Gemfile.lock
    $ git commit -m "Discard changes to Gemfile and Gemfile.lock"
    

Now you can push, and the changes will disappear from your branch.

Note that this is the easier solution but that it leaves your branch in a slightly weird state, both introducing and removing changes to some files. Once you've done this, you can squash your entire branch down to a single commit prior to merging, and all history of the needlessly introduced changes to Gemfile and Gemfile.lock will be discarded.

Community
  • 1
  • 1
user229044
  • 232,980
  • 40
  • 330
  • 338