Git

Git is a distributed version control system.

Git commands

  • git init
    • initialize a directory to be git repository.
  • git status
    • check the statues of a git repository directory.
  • git add [filename]
    • add files to wait for committing.
  • git commit -m "message"
    • commit changes.
  • git log
    • check the log information.
  • git checkout [commit number]
    • go back to the particular commit status. checkout controls “head” pointer.

How Git use git-SHA1 Hash

Example of how git uses the git-SHA1 hash to store HelloWorld.java

  • First, git computes the git-SHA1 hash:
    • HelloWorld.java -> 66ccdc654c9d156d5c796dbe6ed768430c1562a2
  • Git creates a folder called .git/objects/66
    • The 66 is the first two characters of the git-SHA1 hash.
  • Git stores the contents in a file called ccdc654c9d156d5c796dbe6ed768430c1562a2.
    • File is stored in a compressed format (zlib) to save space.

Git Commits

Every commit in git stores (at least):

  • An author
  • A date
  • A commit message
  • A list of all files and their versions
    • Versions are git-SHA1 hashes
  • The parent’s commit ID.

Branching

A common feature in version control systems is the ability to create branches

  • e.g. might “branch” frtom aa if i don’t trust the code in 7e and want to try something else.

use checkout -b [branch name] [parent commit ID] command to create a branch

Merging

git merge [branch name]