/git-ish

Because practice makes perfect

Primary LanguageHTMLMIT LicenseMIT

git-ish

Because practice makes perfect.

This repository is a place to learn and practice git. Learn using the lessons in this README. Practice using any other files in the repo.

Lessons

Exploring Your Repo

  1. Log
    1. Log the last 5 commits on your branch
    2. Log the last 10 commits on your branch, each with oneline of information
    3. Log the last 10 commits on your branch, each with oneline of information, in graph format
    4. Log the last 10 commits for all branches, each with oneline of information, in graph format (depending on your repo, the output here may be the same as the previous step)
Show answer
 
  i.  git log -5 
  ii. git log --oneline -10
  ii. git log --oneline --graph -10
  ii. git log --oneline --graph --all -10
  

  1. Grep
    1. Find all occurences of "mac" in the repo
    2. Find all occurences of "mac" in the repo, ignoring case
    3. Find all occurences of "mac" in .txt files, ignoring case
    4. Find all occurences of "mac" in .txt files, ignoring case, with empty lines btwn matches from different files, headers, and line numbers
Show answer
 
  i.   git grep "mac"
  ii.  git grep -i "mac"
  iii. git grep -i "mac" -- "*.txt"
  iv.  git grep --break --heading --line-number -i "mac" -- "*.txt"
  

Undoing

  1. Changing History
    1. Make changes and commit
    2. Change commit message
    3. Make changes and commit
    4. Make more changes
    5. Add recent changes to latest commit without changing commit message
Show answer
  # make changes and commit
  ii. git commit --amend
  # make changes and commit
  # make more changes
  v.  git commit --amend --no-edit
  

  1. The Three Stages of Git
    1. Make changes, stage them, and commit
    2. Undo commit only (HEAD should now reference previous commit)
    3. Unstage current changes
    4. Undo changes in working directory

Use git show and git status to see the effect of each command

Show answer
 
  i.   # make changes, stage them, and commit
  ii.  git reset --soft HEAD^
  iii. git reset .
  iv.  git checkout .
  

Git Object Model

  1. What Is A Repo?
    1. View the directory containing all git objects in repo
Show answer
 
  i.   tree -I "info|pack" .git/objects  # OR
       ls .git/objects
  

  1. Git Object Model: Investigate Master
    1. master refers to a git object. Print the object type. Does it refer to a blob, tree, or commit?
    2. Pretty print a summary of the object.
    3. List the contents of the object (hint: use ls-tree).
    4. Use a different command to get the same output (hint: use the checksum of the tree from the previous command).
    5. Print the object type of that tree.
    6. Print the object type of one of the blobs in that tree.
    7. Pretty print the blob.
Show answer
 
  i.   git cat-file -t master (master is a reference to a commit)
  ii.  git cat-file -p master
  iii. git ls-tree master
  iv.  git cat-file -p <checksum of tree>
  v.   git cat-file -t <checksum of tree>
  vi.  git cat-file -t <checksum of a blob>
  vii. git cat-file -p <checksum of a blob>
  

  1. Git Object Model: All Refs Lead to Commits
    1. View all references in your git repository
    2. cat the checksum (commit) to which master currently points to
    3. show the commit message related to that checksum
    4. Use checkout to create a new ref called new-branch
    5. Print the checksum to which new-branch currently points to (should be the same as master)
    6. Make a change, stage change, commit it
    7. Print the checksum to which new-branch currently points to (should be different than master)
    8. Delete that new-branch ref
Show answer
 
  # in root directory of repository

i. tree -C .git/refs # OR ls .git/refs

ii. cat .git/refs/heads/master

iii. git show <checksum printed in previous step>

iv. git checkout -b new-branch

v. cat .git/refs/heads/new-branch

vi. # make your changes, stage, and commit however you like

vii. cat .git/refs/head/new-branch

viii. git checkout master && git branch -d new-branch