How do I delete the changes made by the master branch which I deleted?
Asked by Arkl1te:

So I accidentally made changes with the master branch, when I was supposed to do it with my own branch.  

Somehow I ended up like this:

qCZszGR\[1\].png  

Inside the ++red++ area: the ones that I want to **delete**.

Inside the ++blue++ area: the ones that I want to **keep**.

As you may or may not notice, I'm really new to these kind of things. I already deleted the master branch. What should I do to accomplish this?  
[](https://community.atlassian.com/t5/Sourcetree-questions/How-do-I-delete-the-changes-made-by-the-master-branch-which-I/qaq-p/197621?attachment-id=3472){#link_116a150c6fde34}  
[](/tnckb94959/attachments/tnckb94959/sourcetree-questions/5675/1/qCZszGR%5B1%5D.png){#display_116a150c6fde34_0}


Answers:
author: Seth
body: It looks like you pushed your changes to master to the "origin" remote. This is a problem for you - it is dangerous to try to rewrite history that has been pushed to other repositories.

The safest approach is to make an additional commit to master that reverses the changes that aren't supposed to be there. SourceTree can help you with this if you right-click on each bad commit, and choose "Reverse commit".

To fix your Fabian branch - DO NOT PUSH IT. From your screenshot, the change you don't want has not been pushed. This makes it safer to rewrite the history to remove that commit. First, checkout your local Fabian branch. Second, right click on the commit that you want your Fabian branch to be on (probably origin/Fabian). Select "Reset current branch to this commit". In the dialog that comes up, a hard reset will also overwrite your working copy. A mixed reset will keep the changes from the bad commit as Uncommitted changes.

Hope that helps.

comments: author: Johannes Kilian
body: A few words on:"It looks like you pushed your changes to master to the "origin" remote. This is a problem for you - it is dangerous to try to rewrite history that has been pushed to other repositories."This is very true if your repository is a collaborative repository (if other developers use the remote repository as well). In this case it's common agreement not to rewrite the history for remote repositories - whilst other developers still have cloned the original remote repository. \*\*\*Rewriting the history of the remote repository might solve YOUR problems, but causes trouble to all other users of the remote repository.\*\*\*As long you are the single user of the remote repository, it's your free decision to rewrite the history of the remote repository. (This is also valid, if you are a small group of developers. You have to communicate clearly, that you're gonna rewrite the history. Each developer has to finish his work then and push the changes BEFORE you start rewriting the history. During rewriting your fellow developers must not work on the repository. After rewriting each of your fellow developers has to remove their old local repository and clone the (modified) repository again.Rewriting actions depend of your goals:\* if you want to get rid of the commits within the red box, do a "git reset --hard"\* if you want to keep the changes, but want to have it on your own branch "Fabian": simply exchange the branches Fabian and master (first delete the branches an create them at the desired commits again).In both cases you do have to do a "git push --force" to push your modifications to the remote repository


author: sreekumar_menon
body: when you say you deleted master branch, did you delete from your local and is it still there in remote? if you did not push the changes to master, then you are all good , your changes to master is already gone, now you can pull a fresh copy of master branch from server. in this case the changes you did are gone with the deletion.

if you did not delete the local copy of master, and have not pushed your master branch to remote yet ,you could merge the master branch to local branch to move all the commits from master to fabian branch and then do a git "reset" of master branch to that commit . reset will move the pointer back to the commit id you select. alternatively you may git revert the commits in master branch, which will create new commits in master branch to revert the changes in master branch.

hope this helps.