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)?
-
How many commits on your branch? – user229044 Dec 23 '15 at 20:31
-
Does `master` already contain versions of Gemfile and Gemfile.lock? – user229044 Dec 23 '15 at 20:33
-
@meagar Yes, it does. – lakeIn231 Dec 23 '15 at 20:33
-
Are your commits not dependant on the changes in the `Gemfile` (assuming you added gems?) – nathanvda Dec 23 '15 at 22:15
1 Answers
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
:
- Check out your branch, in its current state, with Gemfile and Gemfile.lock
Check out
master
's version ofGemfile
andGemfile.lock
:$ git checkout master -- Gemfile Gemfile.lock
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.

- 1
- 1

- 232,980
- 40
- 330
- 338