We have a practice of squashing all commits of feature branch before merging it in master branch so that we will have one commit of feature branch in master. But accidentally I merged the feature branch into master without squashing. Is there anything than can be done to to resoove the issue.
            Asked
            
        
        
            Active
            
        
            Viewed 365 times
        
    1 Answers
1
            If you haven't made any commit on master after merging that feature branch, you could:
- hard reset in your local repo masterto the commit before that merge
- squash and merge your feature branch
- force push masterand notify any other member working on that repository, for them to reset their own localmasterbranch to that newmasterHEAD.
That is:
git reset --hard <SHA1 before merge>
# squash+merge
git push --force
I have 2 commits in
masterbranch after the merge.
But those where my commits so I know what files I have changed.
Can I still reset my branch from the above method and then commit the next two changes again?
Yes: they can be cherry-picked and replayed on top of the new master HEAD.
Again, once you force push (git push --force) that new branch history, you need to make sure any other collaborator is aware the history change, and reset his/her own local master branch accordingly.
 
    
    
        VonC
        
- 1,262,500
- 529
- 4,410
- 5,250
- 
                    Thanks for the response. I have 2 commits in master branch after the merge. But those where my commits so I know what files I have changed. Can I still reset my branch from the above method and then commit the next two changes again? – Bhawna Joshi Feb 26 '19 at 06:56
- 
                    @BhawnaJoshi Yes: you can actually cherry-pick (https://stackoverflow.com/a/1994491/6309, https://stackoverflow.com/a/881112/6309) those two commits once your reset + (quash,merge) is done. Just make a note of those two SHA1 before starting the process. – VonC Feb 26 '19 at 07:08
