marp |
---|
true |
Lots of good reasons - but the main ones1 are:
- a complete history of changes (which means you can undo)
- branches (you can try new stuff out without breaking things)
- you can trace who did what when, tag versions of your manuscript / code
- submitted, published
- v1.0, feature-release
1 see e.g. "What is version control"
How material changes over time...
There are many version control systems (VCS). But git
comes with some advantages:
- it's distributed (full version history in your local copy)
- corollary: you can work with it anywhere
✈️ or 🚋 (no need for network connection) - it's widely used1
1 see e.g. "Wikipedia / git"
- think of this as snapshots
- what's the state of each file now?
2 [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0)
- each file has a unique fingerprint (
shasum
) - if the file changes, the fingerprint changes, too!
sha
= secure hash algorithmsha
turns text/data into a 40 digit hexadecimal number
hexadecimal numbers?
0...9 10 11 12 13 14 15 # decimal 0...9 a b c d e f # hexadecimal 0 1 10 11 100 101 ... 111 # binary
shasum Introduction.md
# b5acbb35abd2511a4c05e48ef58f8990f139793a Introduction.md
tiny change, e.g. add a space?! and calculate SHA again:
shasum Introduction.md
# 502bbcb5ab4f0d8127396675dd7d17d7d8b55b0a Introduction.md
... completely different.
A similar trick works for a list of directory contents (the "tree")
➡️ tree hash
.
├── analysis
├── stimulusCode
│ └── stims
│ ├── houses
│ ├── normal
│ ├── objects
│ └── scrambled
└── unix-intro
- information about files (aka blobs), their relationship to each other (the tree), the previous state (parent) and a message make up a
commit
$ git cat-file -p HEAD
tree 80fc45cae348efbdbbb652642cf4c22e1ddaaf80
parent b2b3a018fa2569bc5aa54b0b744145f6758bcba7
author Denis Schluppeck <[email protected]> 1517238320 +0000
committer Denis Schluppeck <[email protected]> 1517238320 +0000
fixes http to https
Files
- make a directory,
cd
into it - initialize repo
mkdir test && cd test
git init
- make a text file
test.txt
- write something into it and save it
- add to staging area
- ... and try to commit with a message (
-m
)
git add test.txt
git commit -m 'my first commit'
- you'll see some warning messages
- for (only this first time), set up your
user.name
anduser.email
git config --global user.name "First Last" # your name
git config --global user.email "[email protected]" # your email
- This info is stored on your machine in a little file, which you can inspect
more ~/.gitconfig
git status # read what's there
git commit -m 'my first commit'
git status # read what's there NOW
Currently the repository is local to the machine you are working on, if you want to share with your friends and colleagues on github.com
, follow instructions at:
https://help.github.com/en/articles/adding-an-existing-project-to-github-using-the-command-line
-
Illustrations linked from https://git-scm.com/book/en/v2/ - Creative Commons license CC BY-NC-SA 3.0
-
Details on
shasum
(available as a UNIX command):
man shasum # or
info shasum