0

I'm new to git/version control so please bear with me... I created a branch called mailer snd made a bunch of changes to various files. I'd now like to delete the branch and for the files to go back to as they were before I created the branch. Basically, I'd like my files locally to be as they are on the master branch. Hope that makes sense!

Steve
  • 418
  • 1
  • 4
  • 16
  • 3
    What happened to the git docs? – greybeard Feb 14 '19 at 22:53
  • Possible duplicate of [How do I delete a Git branch both locally and remotely?](https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-both-locally-and-remotely) – Baaing Cow Feb 15 '19 at 01:11
  • Possible duplicate of [Reset local repository branch to be just like remote repository HEAD](https://stackoverflow.com/questions/1628088/reset-local-repository-branch-to-be-just-like-remote-repository-head) – kowsky Feb 15 '19 at 09:12

2 Answers2

0

If I get you right, yiu want to checkout the master branch and discard all changes Try to reset your current changes:

git reset --hard //be careful, this will discard all of your changes

And then:

git checkout master
  • yeah, i wan't to discard all the changes i made on the new branch. – Steve Feb 14 '19 at 22:25
  • So the first command will discard all changes and clean up your WIP and the second one will checkout the master version you had. Run them both – Shaul Badusa Feb 14 '19 at 22:26
  • So it deletes only the changes made on the current branch that your on? – Steve Feb 14 '19 at 22:30
  • The first command will discard all uncommitted changes you have so you be able to checkout the master branch and get the version you wanted – Shaul Badusa Feb 14 '19 at 22:32
  • Does it only discard the uncommitted changes? I made several commits on the branch and I want them all discarded. Just to be clear, I want to go back to the point I was at just before i created the branch. – Steve Feb 14 '19 at 22:34
  • If your branch out from master and made commits only in mailer, so checkout the master will do the magic. The reset will discard all uncommitted changes so you know you are going back to mater without any changes – Shaul Badusa Feb 14 '19 at 22:37
  • So it won't discard committed changes? – Steve Feb 14 '19 at 22:45
  • The checkout will take you back to the state you had on master (it wont discard the changes because the commited changes on the branch will stay there, but the code will rollback to the way its was before all the commits) – Shaul Badusa Feb 14 '19 at 22:48
0

If your whole branch is bad and you want to start anew with a clean branch from master, why not just do that instead of trying to "repair" the failed one?

git checkout master
git checkout -b new-mailer

Another advantage is, when in two days you'll think "Oh! that part I had already working on the failed branch", you'll have your old mailer branch frozen in time and ready for examination and reuse.

And if you need to keep the name mailer for your feature branch for whatever reason, slightly alter the process to this :

# first set the backup
git checkout mailer
git checkout -b old-mailer

# then point the mailer reference to master
git branch -f mailer master
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • This will probably sound like a stupid, but if i checkout to the master branch the files on my computer all stay as they were. How do I get the files on my computer to match the repo of the master branch? Do I have to clone the repo or something? – Steve Feb 15 '19 at 00:55
  • @Steve Based on what you're describing, seems like your local master branch is corrupted too. But now it's a whole new set of questions... do you have a remote from which you can pull a clean version of master? If not, you'll have to go back in master branch history to find the desired state. – Romain Valeri Feb 15 '19 at 01:22