Using GIT effectively

Advanced git log

Ref: https://blog.isquaredsoftware.com/presentations/2021-05-using-git-effectively/?slideIndex=21&stepIndex=0

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

git lg

Or, if you want to see the lines that changed

git lg -p

Resetting options

git reset: move a branch pointer to point to a different commit

  • --soft: keep the current files on disk and in the staging area
  • --mixed: keep the current files on disk, but clear the staging area
  • --hard: clear the staging area and make the working directory look exactly like this specific commit

Reverting commits

git revert: creates new commits with the "opposite" changes of the commits you want to undo

Rebasing Branches

git rebase: rewrite the history of a branch so that it starts from a different base commit than it did originally

Git Internal Data Structures

Look like a "blockchain"

  • Because commits are a linked list based on hashes, and the hashes are based on byte contents of files and other structures, changing any one bit in an earlier commit would have a ripple effect - every hash of each commit after that would be different.
  • Git commit objects are immutable - once created, they cannot actually be changed
  • This means that you can't change history, exactly - you can only create an alternate history