Git  sandbox 

Distributed version control system

What is git?

Distributed version control system.

git repo history git hooks git hooks redux

History

Linus developed git after being frustrated with the state of version control systems in that era. He had experienced the benefits of using a version control system using BitKeeper earlier, but given the restrictive terms, and removal of free tier, he decided to build something of his own.

Fun read, this one https://blog.brachiosoft.com/en/posts/git/

Aside, add “Just for Fun: The Story of an Accidental Revolutionary” to reading list

Internals

  • How does git work?
  • Why does it use filesystem instead of a database like other systems of the time?
  • Is there a bottleneck?
  • Can it be improved?
  • What comes next?

Useful commands

Log

$ git log --oneline    # show one line per commit
$ git log -5 --oneline # show last 5 commits
$ git log -5 --pretty="format:%C(white)%ai %C(yellow)%h %C(blue)%ae %C(reset)%s
$ git log --pretty="format:%C(white)%ai %C(yellow)%h %C(blue)%an %C(green)(%ae) %C(reset)%s" -6
2024-05-29 15:00:00 +0000 b06d833 Bot (bot@example.com) chore(release): 1.0.0 deployment

Amend

Change author name/email for commits already pushed to remote

$ git rebase -i HEAD~4
$ git commit --amend --no-edit --reset-author <commit hash>

Push

git push --force-with-lease

If somebody else built on top of your original history while you are rebasing, the tip of the branch at the remote may advance with their commit, and blindly pushing with –force will lose their work.

This option allows you to say that you expect the history you are updating is what you rebased and want to replace. If the remote ref still points at the commit you specified, you can be sure that no other people did anything to the ref. It is like taking a “lease” on the ref without explicitly locking it, and the remote ref is updated only if the “lease” is still valid.

References