4.6 Git Theory#

Estimated time to complete this notebook: 5 minutes

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")
git log --graph --oneline
*   1cb17d2 Merge branch 'main' of github.com:alan-turing-institute/github-example
| * bb2bdc2 Add another Beacon
* | ce3f482 Add Glyder
*   b88c43f Merge branch 'main' of github.com:alan-turing-institute/github-example
| * 602613b Add a beacon
* | 68a077c Translating from the Welsh
*   c9dd781 Merge branch 'main' of github.com:alan-turing-institute/github-example
| * d224da9 Add Scotland
* | 6c14236 Add wales
* 5cfdbcd Add Helvellyn
* 97f6bd1 Include lakes in the scope
* 2b7a306 Add lakeland
* 41d3b1a Revert "Add a lie about a mountain"
* aebc93c Change title
* cc52d99 Add a lie about a mountain
* b19bc2f 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