Fixing things with GIT

Viewing Commit History

Show last commits,

    git show
    git log -10
    git log -10 --oneline
    git log -10 --pretty=oneline
    git log -10 --pretty=format:"%h - %an, %ar : %s"
    git log -10 --pretty=%B

    git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
    git lg -50

Query the local repository,

    git reflog
    git reflog -1 | sed 's/^.*: //'

Fix commit message(s)

if you forgot to identify yourself,

git commit --amend --reset-author

otherwise if you need to fix e.g. a typo,

git commit --amend

Undo Commit

Undo last commit or also undo the changes in the code,

git reset HEAD^
#git reset --hard HEAD^

Undo a previous commit – go back to the parent of the offending commit,

git rebase -i 03e6c6f^
REMOVE THE OFFENDING COMMIT FROM THE LIST

Undo Push

In case you pushed it already, eventually undo the corresponding push – but this is not practical at all – do not do that – unless you are alone on the project, or you team is really small,

#git push -f

because the other users or possibly your own other systems may re-sync by doing,

#git pull --rebase

References