Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Git: Going back in time

  • 0
  1. Testing stuff on a old commit
# This will detach the HEAD, i. e., it leaves no branch checked out:
git checkout 

# Or:

# This will create a new branch from an old commit. Ideal to play and make new commits.
git checkout -b old-state 
  1. Getting rid of everything done since a specific commit
# If no published commits exist, i. e., it all the commited changes are were not pushed yet!
git reset --hard 
  1. Undo published commits with new commits.
# Delete a commit somewhere in time (the following commits are kept!):
git revert HEAD~2

# Delete the last commit:
git revert HEAD

# Delete the last two commits:
git revert HEAD~2..HEAD

Git: Delete Branch Remote and Locally

  • 0
  1. See all branches:
git branch -a
  1. Delete the branch locally:
git branch -D 
  1. Delete the branch remotely:
git push origin --delete 
DONE!

Git Roll Back

Rolling back to a previous commit:

Only, and only, if you are working by your self!

(This is dangerous in a collaborative environment: we are rewriting history!)
git reset --hard 
git push -f origin
Note, if by any reason you want to have access to the lost commits, use:
git reflog