Fixing things with GIT

Convert to bare

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

https://stackoverflow.com/questions/2199897/how-to-convert-a-normal-git-repository-to-a-bare-one

Convert to normal

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

https://stackoverflow.com/questions/10637378/how-do-i-convert-a-bare-git-repository-into-a-normal-one-in-place/10637882

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

https://stackoverflow.com/questions/28375418/how-to-pull-a-single-file-from-a-server-repository-in-git?noredirect=1&lq=1

Re-fetch everything

git fetch
git reset --hard origin/master

https://stackoverflow.com/questions/3949804/force-overwrite-of-local-file-with-whats-it-origin-repo

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

https://help.github.com/en/articles/changing-a-commit-message https://gist.github.com/nepsilon/156387acf9e1e72d48fa35c4fabef0b4

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 COMMITS 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

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

References

How do I navigate to the earliest commit in a Github repository? https://stackoverflow.com/questions/28533602/how-do-i-navigate-to-the-earliest-commit-in-a-github-repository


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