26
@cczona Cool Git Tricks (That I learn when things go badly.)

Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

Embed Size (px)

DESCRIPTION

Women Who Code lightening talk, August 21, 2012

Citation preview

Page 1: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

@cczona

Cool Git Tricks(That I learn when things go badly.)

Page 2: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

@cczona

Carina C. Zona@cczona

www.cczona.com

Page 3: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

@cczona

I write a detailedcommit message.

(About some other changeset.)

Page 4: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

$ git commit

# Changes to be committed:#...# modified: foo.txt

Page 5: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

$ git commit -v

# Changes to be committed:#...# modified: foo.txt#...-old line+new line

Page 6: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

@cczona

I create long branch names.

(Then have to type all that.)

Page 7: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

git/contrib/completion/git-completion.bash

cp git-completion.bash ~/.git-completion.sh

echo source ~/.git-completion.sh >> ~/.bashrc

Page 8: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

$ git checkout <tab><tab>

0.1-mvp-release marketing-content-dump2.0-public-release masterauthentication-basic optimize-for-webkitbutton-to-pay-me redesign-for-fall-2012live-customer-chat ui-performance-enhance

Page 9: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

$ git checkout b<tab>Switched to branch 'button-to-pay-me'

Page 10: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

@cczona

I use ‘git status’(A lot.)

Page 11: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

git/contrib/completion/git-prompt.sh

cp git-prompt.sh ~/.git-prompt.sh

echo source ~/.git-completion.sh >> ~/.bashrc

Page 12: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

#master|MERGE $

#master|REBASE-i $

#master + $ # tracked

#master $ $ # stash

#master> $ # upstream

Page 13: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

3 pending on foundation#master

~/repo/foundation/css $ git add .

3 pending on foundation#master

~/repo/foundation/css $ git commit

...

0 pending on foundation#master

~/repo/foundation/css $ touch new.txt

1 pending on foundation#master

~/repo/foundation/css $

Page 14: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

@cczona

I pathologically avoid `git add .`

(Now.)

Page 15: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

$ git grep -e stupid \ --and -e boss

index.html: The boss is a stupidhead

Page 16: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

$ git grep -e promotion \ --or -e bargain \ --not -e (coupon|discount)

Page 17: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

# working area tracked$ git grep

# working area tracked & untracked$ git grep --untracked

# working area all (ignore .gitignore)$ git grep --untracked --no-exclude-standard

# staged$ git grep --cached

Page 18: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

# arbitrary commit $ git grep“2007”HEAD^

# range $ git grep “2007”c0c1e80..141a16a

# every commit$ git grep“2007”$(git rev-list --all)

Page 19: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

@cczona

(Time machine needed.)

I don’t necessarily detect a problem

immediately.

Page 20: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

$ git bisect start$ git bisect bad HEAD$ git bisect good v2.0

Bisecting: 44 revisions left to test after this (roughly 6 steps)...b047b0 is first bad commit

Page 21: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

@cczona

I sometimes need to pretend a commit never happened.(Like, even rebase ain’t gonna cut it.)

Page 22: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

$ git checkout HEAD~10

...

$ ls

about.html

contact.html

uber-secret-never-commit-this.txt

Page 23: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

(leaving out many crucial details...)

filter-branch # remove from local commits...

reflog expire # make artifacts eligible for garbage collection

gc # do the garbage collection

push --force # rewrite remote history

Page 24: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

@cczona

Git can be a pain.It also has cool tricks to take pain away.

(Whew.)

Page 25: Cool Git Tricks (That I Learn When Things Go Badly) [1/2]

@cczona

Questions?Carina C. Zona

www.cczona.com@cczona