git
Lots of good reasons - but the main ones1 are:
1 see e.g. “What is version control”
If you are collaborating on code / docs, in addition:
git
?There are many version control systems (VCS). But git
comes with some advantages:
1 see e.g. “Wikipedia / git”
git
does snapshotsshasum
)sha
= secure hash algorithmsha
turns text/data into a 40 digit hexadecimal numberhexadecimal 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
of a fileshasum Introduction.md
# b5acbb35abd2511a4c05e48ef58f8990f139793a Introduction.md
tiny change, e.g. add a space?! and calculate SHA again:
shasum Introduction.md
# 502bbcb5ab4f0d8127396675dd7d17d7d8b55b0a Introduction.md
… completely different.
git
nitty-gritty – for data club 😀the sha
actually refers to the
"blob + <size in bytes> + \0 + <the file contents>"
you can try this out by
echo 'Hello, World!' | git hash-object --stdin
# leads to
8ab686eafeb1f44702738c8b0f24f2567c36da6d
Note: the filename doesn’t contribute to the sha
of the file / blob … which means renaming files is cheap (doesn’t use up space)
A similar trick works for a list of directory contents (the “tree”)
:arrow_right: tree hash
.
├── analysis
├── stimulusCode
│ └── stims
│ ├── houses
│ ├── normal
│ ├── objects
│ └── scrambled
└── unix-intro
commit
commit
$ git cat-file -p HEAD
tree 80fc45cae348efbdbbb652642cf4c22e1ddaaf80
parent b2b3a018fa2569bc5aa54b0b744145f6758bcba7
author Denis Schluppeck <denis.schluppeck@gmail.com> 1517238320 +0000
committer Denis Schluppeck <denis.schluppeck@gmail.com> 1517238320 +0000
fixes http to https
</small>
you (on your own), several different computers
you, a couple of collaborators,+ code that changes a lot
you want to share materials with lots of people (details change: maybe once a year, maybe more often…)
new idea / analysis: worth creating a new repo (private??)
on laptop: work on code, git add
, git commit
, git push
on desktop: git clone
, use code (but if you find a bug while running on lab machine …
fix and push back to repo)
</small>
# they should make a new TRACKING BRANCH
git checkout -b whacky-idea-branch
# work on there, git add / commit / push...
git checkout main
git merge whacky-idea branch # when ready ;)
</small>
markdown
(which gets converted to HTML via jekyll
)cd
into itmkdir test && cd test
git init
test.txt
-m
)git add test.txt
git commit -m 'my first commit'
user.name
and user.email
git config --global user.name "First Last" # your name
git config --global user.email "me@gmail.com" # your email
macos
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