I'm facing i want to remove my commit from main repository. the code has pushed with my unwanted local changes. So how can i revert back that. i'm using source tree and git as well. please help me.
            Asked
            
        
        
            Active
            
        
            Viewed 85 times
        
    0
            
            
        - 
                    Move your local master to the right location and push -f. – Thorbjørn Ravn Andersen Jan 12 '15 at 09:36
 
1 Answers
2
            Try git revert. It doesn't change history, but "unmakes" a single commit by applying the reverse actions to the source as a new commit.
You can specify a range of commits for revert with the .. syntax (detailed explanation):
git revert -n abcd1234..fedc0987
(The n flag prevents autocommits. abcd... stands for a unique commit ID hash.)
        Sascha Wolf
        
- 18,810
 - 4
 - 51
 - 73
 
        ojrask
        
- 2,799
 - 1
 - 23
 - 23
 
- 
                    
 - 
                    Oh, those are commit identifier hashes. By using `git log` in the terminal you can see the unique hash for each and every commit in the Git repo. On Source Tree there should be unique hashes in each commit's info somewhere I presume. I used `abcd...` as an example. – ojrask Jan 12 '15 at 06:06
 - 
                    
 - 
                    Commit: f6341b46f76ddc1d6a7d2b387f780a101d7850a8 .... are u mentioning this? – srini Jan 12 '15 at 06:07
 - 
                    
 - 
                    It will remove the commit changes from the branch you're on. If the commit doesn't exist on a certain branch, the `revert` will not work. Once the command is executed, just push the new commit (result of `revert`) to the main repo and it will act like any normal commit. The good side of this is a that `revert` doesn't undo history so your team members can use the new commit without headaches. – ojrask Jan 12 '15 at 06:10
 - 
                    
 - 
                    Yes and no. Yes as in others can undo the changes of your undo-commit (which used `revert`). No as in `revert` prevents conflicts in history and content. – ojrask Jan 12 '15 at 06:20
 - 
                    1@ojrask For a detailed explanation for the "range of commits" syntax (`..`) take a look at [this chapter](http://git-scm.com/book/it/v2/Git-Tools-Revision-Selection) from the progit book. I've also edited the answer with the reference. – Sascha Wolf Jan 12 '15 at 09:03