Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git change branch, but don't change files in workspace

This is similar to my another question ( Switch to another branch without changing the workspace files ) but solution that worked there, doesn't work now.

I needed to remove some changes, which were long time ago pushed to remote master. So I don't want to remove commits from master, but I want to change the files just like these changes were reverted. So I did this:

  1. While on master, git branch limits
  2. git checkout limits
  3. git rebase --interactive <commit before the ones I wanted to remove>
  4. in interactive console I removed the commits with changes I wanted to revert

So now in limits I have the code like I'd like it in master. How can I "move" it to master? With the code from limits I'd like to change to master branch, but without changing any file in workspace, so I can then commit the changes as a new change to master.

like image 879
amorfis Avatar asked Jul 13 '12 15:07

amorfis


1 Answers

The answer to your stated question is:

$ git checkout master             # switch to master branch

$ git reset --hard limits         # hard-reset it to the limits commit
$ git reset --soft master@{1}     # move the reference back to where it was, but
                                  #  don't modify the working tree or index

This will leave your working tree and index exactly as it would be if you had limits checked out, but you will be on the master branch at its original location.


However, the proper way to do something like this would be to git revert each change that you are trying to undo.

like image 147
vergenzt Avatar answered Sep 24 '22 19:09

vergenzt