Professional Documents
Culture Documents
Oh Shit Git Zine
Oh Shit Git Zine
slmansitreset
In the first and second
form, copy entries from
<tree-ish> to the index. In
the third form, set the
current branch head (HEAD)
to <commit>, optionally
modifying index and
omaybegitreseH.fm working tree to match. The
<tree-ish>/<commit>
actual
0 defaults to HEAD in all
forms.
g
manpage eviesnthnisglish
Tien oes
t t
n n
Katie Julia
By Katie Sylor-Miller & Julia Evans
Website: https://ohshitgit.com
Cover art by Deise Lino
Table of contents
git fundamentals
a SHA is
always the same code 4
every commit has a parent commit 5
a branch reference to a commit
is a 6
HEAD is the commit you have checked out 7
mistakes you can't fix 8
Emmet
out a SHA will always give you the exact same code. It's
like saving your game so that you can go back if you die
You can check out a commit like this: SHAs are long
but you can
git checkout 3f29ab just use the
first 6chars
This makes it way easier to recover from mistakes!
IIOamJ 1lam
qgoeothnietisaii.mzitsmhaEiIioTg.e
4
A branch is a
pointer
to a commit
A branch in git is a pointer to a commit SHA
$ cat .git/refs/heads/master
t
this is just a text file
with the comimit SHAmaster
points at B
EITnenm.tt
2abcdeJ HEAD make cats blue
to
parent Tfeefffe HEAD add cats
f
ent la9J2eab HEAD
Grapnadr
fix typo
a git clean
or directory
git checkout BRANCH FILE
8
I need to change the message
f
fyard my last commit.ir
on
i
git commit --amend I
I
if you run
git commit but change
EIIIIifIIinifigffiatingigassibitsalisnstauitting
I
fsfFL.s I committed but I neyed to
gf
yard
make one small change
i
git commit --amend --no-edit i
re
oh s.tsii
rqgiethisoi.si
enJ
before committing9
I
I accidentally committed
to the
gffffffs wrongbranch
yard
Check out the correct branch correct i throng
ri
git checkout correct-branch
cherrypick makes a
new commit with the
Same changes as A
but a differentparent
Add the commit you wanted to it I
correct
wrong
git cherry-pick COMMIT_ID
f
use git logwrong branch
to find this
Delete the commit from the wrong branch
correFF
git checkout wrong-branch wrong
git reset --hard HEAD^ I
i
I
I committed something to
fFF master that should have been
git status
git reset --hard HEAD~
careful
T
i iti i en
12
I tried to run diffa
f
fyard but nothing happened
ai
i
Suppose you've edited 2 files I
$ git status
On branch master
Changes to be committed: staged changes
added with
modified: staged.txt it add
Changes not staged for commit: g
unstaged
modified: unstaged.txt
changes
Here are the 3 ways git can show you a diff for
these changes:
p
git diff --staged: staged changes
B git diff HEAD: staged+unstaged changes
p
git diff --stat gives you a summary of
which files were changed & number of
added/deleted lines
p git diff --check checks for merge
conflict markers & whitespace errors
13
Ihave a
JIFFIES merge conflict
yard
Suppose you had master checked out and ran
git merge feature-branch.
When that causes a merge conflict, you'll see
something like this in the files with conflicts:
<<<<<<< HEAD
if x == 0:
return false code from master
=======
if y == 6:
return true
elif x ==0:
return false Euterimanan
>>>>>>>> d34367
To resolve the conflict:
j isIoo
Meld lmeldmerge.org is
A a
greatchoice
14
I committed a file that
gfjff.IS
yard
should be ignored 9
15
I started rebasing and
f
f Tf I have
now 10000000
B
conflicts to fix
This can happen when you're rebasing many
commits at once.
i
want to
fsfFEk.Icommit split my
gfperf into 2 commits
git stash
ii
17
I want to undo something
fF
fyard from 5 commits ago
Run:
git revert SHA
i
I did something terribly wrong
fFE does git have a magic
perf time machine
Yes! It's called git reflog and it logs every single thing
you do with git so that you can always go back.
i
245fc8d HEAD@{2} rebase -i (start): checkout master
b623930 HEAD@{3} commit: add cool feature
01d7933 HEAD@{4} checkout: moving from master
to my-cool-branch