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/^.*: //'

Re-fetch a single file

git fetch
git checkout origin/master -- folder/file

Re-fetch everything

git fetch
git reset --hard origin/master

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

Get rid of everything

git log --reverse --oneline --pretty=format:"%h - %an, %ar : %s" | head -10
git rebase -i 953b5a2^
git push -f

Fix local vs remote

git pull origin master

and check

git log -p -20


How do I navigate to the earliest commit in a Github repository?

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