diff --git a/README.md b/README.md index 1ed3910..3d52bc0 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,11 @@ For clarity's sake all examples in this document use customized bash prompt in o - [I want to discard my local, uncommitted changes](#i-want-to-discard-my-local-uncommitted-changes) - [I want to add changes in one file to two different commits](#i-want-to-add-changes-in-one-file-to-two-different-commits) - [I want to remove a file from git but keep the file](#i-want-to-remove-a-file-from-git-but-keep-the-file) +- [Deleting Commits and Tags](#deleting-commits-and-tags) + - [Delete/remove last pushed commit](#deleteremove-last-pushed-commit) + - [Delete/remove arbitrary commit](#deleteremove-arbitrary-commit) + - [Delete tag](#delete-tag) +- [Clone all submodules](#clone-all-submodules) @@ -528,3 +533,41 @@ If you want to only reset to some commit between origin and your local, you can ```sh (master)$ git rm --cached log.txt ``` + + +## Deleting Commits and Tags + +If you need to delete pushed commits, you can use the following. However, it will irreversabily change your history, and mess up the history of anyone else who had already pulled from the repository. In short, you should never do this, ever. + + +### Delete/remove last pushed commit + +```sh +git reset HEAD^ --hard +git push -f [remote] [branch] +``` + + +### Delete/remove arbitrary commit + +```sh +git rebase --onto SHA1_OF_BAD_COMMIT^ SHA1_OF_BAD_COMMIT +git push -f [remote] [branch] +``` + + +### Delete tag + +```sh +git tag -d +git push :refs/tags/ +``` + + +## Clone all submodules + +```sh +git clone --recursive git://github.com/foo/bar.git +# If already cloned: +git submodule update --init --recursive +```