Git Survival Guide

Deleting Tag

How to delete the tag v1.0 both local and remote repository:

git tag -d v1.0
git push origin :refs/tags/v1.0

Undo a Commit

How to revert back to a previous commit, undoing any previous commits:

git reset HEAD~1
git push -f

The number in above command states how many commits to undo. To revert only last commit, the command git reset HEAD^ can be used as well.

The push fill force the update of the remote repository. This must be handled with care! Things will really get messed up if some commits of the remote repository will be cancelled while other people are working with the same repo.

Delete a File

How to remove a unnecessarily committed file from the repository:

git rm –cached file.ext

Change Commit Message or Edit Last Commit

To change the commit message of the previous commit (when no other changes has been done in the working tree):

git commit --amend

The same command can be used to add additional modifications to the file set already committed:

git commit –m ‘the commit’
git add missing_file.ext
git commit --amend