 How can I locally cancel all the changes made in a commit?
How can I locally cancel all the changes made in a commit?

                

        

        


    
    
                
I have a specific directory where the sources where modified in a specific commit 0x0x0x0x0. After that commit have been many other commits all on the master. 

I want to cancel that commit 0x0x0x0x0 and locally(not upstream) in this specific directory have the code prior to  when this commit was made. 
What git commands can I run for this?

Later edit: I want just that specific commit canceled not the subsequent changes. As code it doesn't affect me since it is an independent module. Also I will not use this local repository for committing further upstream.
    

        

    
    
        
            asked Feb 26, 2013 at 14:58
        
        
    
    
        
    
    
        Eduard FlorinescuEduard Florinescu17.5k28 gold badges120 silver badges185 bronze badges
        
    

    





            1
    




                
                
                
                    


                                    

        

        


    
    
If you want to go back to before the commit was introduced, so effectively removing its changes and all changes that happened afterwards (in other commits), you can do the following:


Check out a new branch to the old version, so you don’t lose any information but can just restart from the old state: git checkout -b <newbranchname> commithash~1
Reset your current branch to the old version, effectively removing all the commits from the history if no other branch points to them: git reset --hard commithash~1


But if you just want to undo said commit while keeping all the changes that were made afterwards, you can just do this:

git revert commithash

    
    
    
        
            answered Feb 26, 2013 at 15:03
        
        
    
    
        
    
    
        pokepoke386k80 gold badges584 silver badges626 bronze badges
        
    

    





            0
    


                                    

    
    
It's possible to return to any commit with the following command: 

git reset --hard commit_identifier

Note: to obtain the commit identifier use git log command

You can also reset the last commit with command:

git commit --amend

Take a look to the next link for more information: 

http://www.kernel.org/pub/software/scm/git/docs/git-reset.html
    
    
    
        
            answered Feb 26, 2013 at 15:14
        
        
    
    
        
    
    

    



                        


                            
                                
                            
                
            