Search code examples
gitbranchrevert

fix 'unbroken' code with git commit and revert (my stupid way)?


I was working on branch A when suddenly everything crashed and stopped working. I thought I might broken something in my code so I committed my changes and created new branche B from branch A to keep it as a backup. then I revert branch A to the last working commit, and start trying to fix any possible bugs. I realised later that the server had a problem not my code. So I deleted branch A and contenue working in branch B. I did this because I'm no git expert so I sorted things out with my little knowledge. I believe there should be much easer, cleverer and more appropriate ways to solve such a problem than my "very stupid" way :) Any suggestion?


Solution

  • You could have reset A branch to the last working commit again,

    git checkout branch_A
    git reset --hard last_working_commit_id  
    

    merged the "unbroken" code from B back to A branch,

    git merge branch_B
    

    then delete B branch and continue working with A branch.

    git branch -d branch_B