Fixing things with GIT

Convert to bare

mv .git/ ../repo.git/
cd ../repo.git/
git config --bool core.bare true

Convert to normal

git config --local --bool core.bare false

Viewing Commit History

Show last commits,

#git show
#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 -10

With diffs,

git log -p

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

and in case you already pushed it before,

git push --force

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^

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


Nethence | Doc | Pub | Lab | Pbraun | SNE Russia | xhtml