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

No comments:

Post a Comment