Skip to content

Instantly share code, notes, and snippets.

@zenithtekla
Last active July 17, 2016 05:45
Show Gist options
  • Save zenithtekla/a9badfdb372d37f935db50cf7b65ac5b to your computer and use it in GitHub Desktop.
Save zenithtekla/a9badfdb372d37f935db50cf7b65ac5b to your computer and use it in GitHub Desktop.
Some git commands
Deleting last commit
$ git reset HEAD^ --hard
$ git push -f origin master
$ git cherry-pick <rev-hash>
# Proceed with git push if shell message seems fine, Otherwise do git commit to ascertain if there are changes in files
# and resolve with git add, rm.
$ git commit
$ git push -f origin <branch|master>
Case 2: Delete the second last commit
Let's say the bad commit dd61ab32 is not the top commit, but a slightly older one, e.g. the second last one.
We want to remove it, but keep all commits that followed it.
In other words, we want to rewrite the history and force the result back to mathnet/master.
The easiest way to rewrite history is to do an interactive rebase down to the parent of the offending commit:
$ git rebase -i dd61ab32^
1: pick dd61ab32
2: pick dsadhj278
3: ...
remove the fist pick
$ git push mathnet -f
Case 3: Fix a typo in one of the commits
simply replace its pick with edit and save/exit
source: http://christoph.ruegg.name/blog/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.html
Remembered but worth to save if losing memory of it:
On Vim, INSERT to edit
ESC | Ctrl C
:wq! to save & exit Vim
`git add . ` (to add new changes)
git reset (to undo that, but preserving my new code).
`git commit -m 'r*` (to add a new commit)
git commit --amend (to undo that, but preserving my new code)
git clean (to undo that and revert to my last code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment