Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 438
moey Avatar asked Mar 26 '12 00:03

moey


People also ask

What command is used to remove a last commit?

To undo changes associated with a specific commit, developers should use the git revert command. To undo every change that has happened since a given commit occurred, use git reset.


2 Answers

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
like image 61
GoZoner Avatar answered Sep 22 '22 07:09

GoZoner


Just do

git branch for_later
git reset --hard bbbbbb

Of course, don't do this if cccccc is already pushed. In that case, use revert.

like image 36
manojlds Avatar answered Sep 22 '22 07:09

manojlds