4.6 Git Theory
Contents
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")
os.chdir(working_dir)
%%bash
git log --graph --oneline
* 1acc420 Merge branch 'main' of github.com:alan-turing-institute/github-example
|\
| * 5187cad Add another Beacon
* | 2218446 Add Glyder
|/
* 79a3294 Merge branch 'main' of github.com:alan-turing-institute/github-example
|\
| * 153e1b1 Add a beacon
* | 970500e Translating from the Welsh
|/
* f8080e1 Merge branch 'main' of github.com:alan-turing-institute/github-example
|\
| * c5d6b91 Add Scotland
* | 79f56b9 Add wales
|/
* 7267535 Add Helvellyn
* bb45a08 Include lakes in the scope
* 35a257c Add lakeland
* 65ba0b3 Revert "Add a lie about a mountain"
* e6c8259 Change title
* 589000c Add a lie about a mountain
* bb05a4f 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 commitgit reset --soft <commit>
: Move local repository branch label to that commit, leave working dir and index unchangedgit 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