Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Branch newbie - How to reverse?

Not sure if this is a proper way to work with branches.

  • I had this application on structure A.
  • I created a branch Z while I was on that structure A (but I kept my self on the master branch working).
  • While working (on the master branch), I changed that structure and I end up messing the all thing. :)
  • I've never commit nor added those new files to the rep.

Request:

  • I need to revert to the structure existing on the last commit. Revert All Uncommitted changes and also remove new files and folders that may have been added.

How can this be done?

like image 349
MEM Avatar asked Apr 27 '11 14:04

MEM


1 Answers

If you created a separate branch that got messed up, all you need to do is switch back to the one you were on before: git checkout A (assuming A is the name of the branch you were on... or maybe it's master).

You can delete the bad branch later, if you want, with git branch -d <branchname> and maybe throw in a -f too, if there are unmerged commits.

Edit: If your repository contains lots of bad changes you want to remove, you can use git reset --hard HEAD to undo them. If there are new files (not tracked by git), git clean -fd will remove them all. Obviously, use with discretion as they will not be recoverable by git.

like image 195
Dan Breen Avatar answered Oct 05 '22 11:10

Dan Breen