Here’s some more Strange Loop 2011 material–this time about a talk on git given by Scott Chacon (@chacon)!
In his talk, Scott focuses on demystifying git’s reset
command through an explanation of git’s three trees: HEAD
, index
, and the working tree
. Toward the end of the talk, he also includes some of Git’s plumbing goodies that can be useful in local scripts for automatic backup, cleaning past commits, and so forth.
Hope you enjoy the notes. As always, I typed quickly and so guarantee absolutely no accuracy. You might reference these notes with his slides (warning: PDF).
git add
everything, rm
all files, and git commit
would still work just finegit status
tells you the diff of the three treesgit reset [file]
git add [file]
HEAD
and make index look like thatgit reset [commit]
--soft
: move HEAD
to target
git reset --soft HEAD~
HEAD~
: parent of HEAD
[--mixed]
: then copy to index
HEAD
is pointing at and makes your index look like that.--hard
– then copy to work dir
git reset --soft HEAD~2; git commit
HEAD
back tw ocommits, keep indexgit checkout
git checkout [commit] [path]
git checkout [commit]
git reset master
will move your index to where the branch startedgit checkout master
will move HEAD
to point to mastergit add --patch [file]
git reset --patch (commit) [file]
git checkout --patch (commit) [file]
git add -p
git commit --amend
== git reset --soft HEAD~; git commit ...
git log --stat (branch)
rev-parse
git rev-parse origin/master
git rev-parse master~163^2~3^2
– walks backwards, does some cool stuff. Figures out its SHA.git rev-parse master~163^2~3^2..origin/master
hash-object
git hash-object -w ~/.sshid_rsa.pub
echo 'my awesome value' | git hash-object -w --stdin
ls-files
git ls-files -s
: shows you your staging arearead-tree
git ls-files -s # show index git ls-files -r HEAD # show index git read-tree HEAD~2 # basically same as git reset
write-tree
git write-tree
: tells you the tree that a commit would make if you commited it.commit-tree
echo 'my commit message' | git commit-tree
git commit
update-ref
git branch
mechanismgit update-ref refs/heads/newbranch
symbolic-ref
git symbolic-ref HEAD refs/heads/newbranch
I like learning new things. Previously: Kenchi founder, eng & ops teams at Stripe from 2012-2019. Say hi! 🏳️🌈