Git Theory

The revision Graph

Revisions form a GRAPH

import os

top_dir = os.getcwd()
git_dir = os.path.join(top_dir, "learning_git")
working_dir = os.path.join(git_dir, "git_example")
os.chdir(working_dir)
%%bash
git log --graph --oneline
*   71cdbbe Merge branch 'main' of github.com:alan-turing-institute/github-example
|\  
| * 1fe0962 Add another Beacon
* | afd1a13 Add Glyder
|/  
*   807e3f8 Merge branch 'main' of github.com:alan-turing-institute/github-example
|\  
| * 0809fde Add a beacon
* | ea47bd7 Translating from the Welsh
|/  
*   2055725 Merge branch 'main' of github.com:alan-turing-institute/github-example
|\  
| * caaf510 Add Scotland
* | 54d3883 Add wales
|/  
* 2e2ee6e Add Helvellyn
* e8c018d Include lakes in the scope
* d9160c8 Add lakeland
* fa4dd70 Revert "Add a lie about a mountain"
* 366e9c0 Change title
* 0c51bea Add a lie about a mountain
* d833c8a First commit of discourse on UK topography

Git concepts

  • Each revision has a parent that it is based on

  • These revisions form a graph

  • Each revision has a unique hash code

    • In Sue’s copy, revision 43 is ab3578d6

    • Jim might think that is revision 38, but it’s still ab3579d6

  • Branches, tags, and HEAD are labels pointing at revisions

  • Some operations (like fast forward merges) just move labels.

The levels of Git

There are four Separate levels a change can reach in git:

  • The Working Copy

  • The index (aka staging area)

  • The local repository

  • The remote repository

Understanding all the things git reset can do requires a good grasp of git theory.

  • git reset <commit> <filename> : Reset index and working version of that file to the version in a given commit

  • git reset --soft <commit>: Move local repository branch label to that commit, leave working dir and index unchanged

  • git reset <commit>: Move local repository and index to commit (“–mixed”)

  • git reset --hard <commit>: Move local repostiory, index, and working directory copy to that state