Search code examples
gitversion-controlrevert

How to Temporarily Remove the Last Commit with Git?


Suppose I have the following git commits:

  1. aaaaaa
  2. bbbbbb
  3. cccccc (the latest)

I would like to go back to bbbbbb and continue the development from there. Essentially, I want to remove cccccc for now and be able to retrieve it in the future (I know I'd still need the cccccc). Should I revert cccccc or rollback to bbbbbb?


Solution

  • Just do:

    git checkout -b dev_on_b bbbbbbb
    

    which will leave the branch with cccccc alone and give you a new branch starting from bbbbbb. When you want to return to using ccccc you can do either of:

    git merge branch_with_cccccc          # bring cccccc into dev_on_b
    

    or

    git checkout branch_with_ccccc