Basics of Git: Part Two
In the last article we learned about git stage, commit, stash, reset and remove now we will move to some other commands to give this series a proper ending for basic idea and to get starting. Going back a commit This is essentially destroying history. So be cautious of this one. If we want a to go back to one commit behind or we want to delete a commit - git reset --hard HEAD~1 To revert to a specfic commit - git reset commit_id - git revert commit_id Then if we want to push that to remote (origin) - git push -f origin main checking a previous commit If we want to go back and just check a commit then - git checkout commit_id We cannot work while in this checkout mode After checking that commit and want to comeback to present - git checkout master Rebase Merge and rebase works in same way but with slight variation. Merge squashes all the commit and puts it as one commit in the branch. On the other hand rebase takes those commits and puts infront of the branch. Image below describes it well. ...