Slide 1

Slide 1 text

Insurance for your Versioning Lifestyle

Slide 2

Slide 2 text

What’s In This Talk?

Slide 3

Slide 3 text

What’s In This Talk? ‣ What’s here... ‣ Things that stumped me ‣ Things I wish I’d known sooner ‣ Things that increase my productivity ‣ What’s not here... ‣ Hand holding What’s In This Talk?

Slide 4

Slide 4 text

I’m Overzealous What I Had To Leave Out ‣ Garbage Collection ‣ How and why SHAs work ‣ The .git directory ‣ How to sign your tags ‣ Why moving/ renaming and copying files is important ‣ Advanced Git aliases ‣ Working with multiple remotes ‣ Setting up your local machine as a Git server ‣ Details about how Git clones a repository and the differences between protocols ‣ Differences between .. ... in ref specs ‣ Differences between ^ and ~ ‣ Why ‘git push’ usually Just Works

Slide 5

Slide 5 text

I’m Overzealous What I Had To Leave Out ‣ What is HEAD and how does Git keep track of it ‣ How to allow Git bisect to save your sanity ‣ How to use the reflog to get yourself out of a jam ‣ What’s the difference between a submodule and a subtree

Slide 6

Slide 6 text

What to Expect That I’m Expecting

Slide 7

Slide 7 text

What I Expect ‣ clone ‣ push and pull ‣ Create branches and basic merges ‣ Passing familiarity with ‘the stage’ ‣ commit but typically just using --all ‣ merge almost exclusively into master What I Expect

Slide 8

Slide 8 text

Beginners Tips

Slide 9

Slide 9 text

Beginners Tips

Slide 10

Slide 10 text

Beginners Tips

Slide 11

Slide 11 text

Beginners Tips

Slide 12

Slide 12 text

Beginners Tips

Slide 13

Slide 13 text

Beginners Tips

Slide 14

Slide 14 text

Beginners Tips

Slide 15

Slide 15 text

Beginners Tips

Slide 16

Slide 16 text

Beginners Tips Git GUIs

Slide 17

Slide 17 text

Plumbing

Slide 18

Slide 18 text

Plumbing Plumbing ‣ Working with Objects ‣ hash-object ‣ cat-file ‣ count-objects ‣ verify-pack

Slide 19

Slide 19 text

Plumbing Plumbing ‣ Working with a Hierarchy ‣ write-tree ‣ read-tree

Slide 20

Slide 20 text

Plumbing Plumbing ‣ Working with Commit Objects ‣ commit-tree ‣ rev-list

Slide 21

Slide 21 text

Plumbing Plumbing ‣ Working with References ‣ update-ref ‣ symbolic-ref ‣ show-ref

Slide 22

Slide 22 text

Plumbing Plumbing ‣ Working with the Index ‣ update-index ‣ diff-index

Slide 23

Slide 23 text

Plumbing Plumbing ‣ Miscellaneous ‣ merge-base ‣ rev-parse

Slide 24

Slide 24 text

Data Safety

Slide 25

Slide 25 text

Data Safety Data Safety ‣ Plumbing Commands ‣ hash-object ‣ cat-file ‣ count-objects ‣ verify-pack ‣ write-tree ‣ read-tree ‣ commit-tree ‣ rev-list ‣ merge-base ‣ rev-parse ‣ update-index ‣ diff-index

Slide 26

Slide 26 text

Rewriting History

Slide 27

Slide 27 text

Rewrite History Cherry Picking # from the command line $ git cherry-pick D A C B D* D

Slide 28

Slide 28 text

Rewrite History Rebasing

Slide 29

Slide 29 text

Rewrite History Rebasing

Slide 30

Slide 30 text

Rewrite History Merge Conflict Bad A Bevis and Butthead C B Beavis and Butthead Bevis and Butthead!!! D Beavis and Butthead!!!

Slide 31

Slide 31 text

Rewrite History Merge Conflict Bad A Bevis and Butthead C B Beavis and Butthead Bevis and Butthead!!!

Slide 32

Slide 32 text

C* Rewrite History Merge Conflict Bad A Bevis and Butthead Beavis and Butthead Beavis and Butthead!!! B

Slide 33

Slide 33 text

C* Rewrite History Merge Conflict Bad A B C

Slide 34

Slide 34 text

Rewrite History The Rebase Command A C B D

Slide 35

Slide 35 text

C* D* Rewrite History The Rebase Command # from the command line $ git rebase --onto B A D A C B D

Slide 36

Slide 36 text

Rewrite History The Rebase Command # from the command line $ git rebase B D A C B D HEAD

Slide 37

Slide 37 text

Rewrite History The Rebase Command # from the command line $ git rebase B A C B D HEAD

Slide 38

Slide 38 text

Rewrite History Preserving Merges # from the command line $ git rebase --onto B A E A C B D E

Slide 39

Slide 39 text

Rewrite History Preserving Merges # from the command line $ git rebase --onto B A E A C B D E C* D*

Slide 40

Slide 40 text

Rewrite History Preserving Merges # from the command line $ git rebase -p --onto B A E A C B D E C* D* E*

Slide 41

Slide 41 text

Rewrite History Interactive Rebasing D B Bevis and Butthead Bevis and Butthead!!! Beavis and Butthead!!! C A # from the command line $ git rebase --interactive --onto A A D

Slide 42

Slide 42 text

Rewrite History Interactive Rebasing # from the command line $ git rebase --interactive --onto A A D pick B Add my favorite TV Show pick C Give it some awesome sauce pick D I can’t BELIEVE I MISSPELLED IT! edit B Add my favorite TV Show pick C Give it some awesome sauce pick D I can’t BELIEVE I MISSPELLED IT!

Slide 43

Slide 43 text

Rewrite History Interactive Rebasing D B Bevis and Butthead Bevis and Butthead!!! Beavis and Butthead!!! C A E Beavis and Butthead

Slide 44

Slide 44 text

Rewrite History Interactive Rebasing D B Bevis and Butthead Bevis and Butthead!!! Beavis and Butthead!!! C A E Beavis and Butthead F Beavis and Butthead!!!

Slide 45

Slide 45 text

Recipes

Slide 46

Slide 46 text

Recipes Moving Branch Refs Safely $ git reset --hard $MY_SHA # from the command line $ git checkout -B $MY_BRANCH $MY_SHA

Slide 47

Slide 47 text

Recipes Creating a Parallel Universe # from the command line $ git checkout --orphan $MY_BRANCH

Slide 48

Slide 48 text

Recipes

Slide 49

Slide 49 text

Recipes Removing a File from History # from the command line $ git filter-branch --index-filter ‘ git rm -rf --cached --ignore-unmatch $SECRET_FILE ‘ --prune-empty -- --all

Slide 50

Slide 50 text

Recipes Remove Specific Contents From Files # from the command line $ git filter-branch --index-filter ' if [ -f $FILE_WITH_SECRET_STUFF ]; then sed -i ’s/$SECRET_STRING_TO_REMOVE//g’ $FILE_WITH_SECRET_STUFF; git add -A fi' -- --all

Slide 51

Slide 51 text

Recipes Splitting a Repository

Slide 52

Slide 52 text

Recipes Create the Repository for the Library # from the command line $ git clone file://path/to/my/proj/repo /new/path/to/my/lib/repo $ cd /new/path/to/my/lib/repo $ git filter-branch --subdirectory-filter my_lib_dir --prune-empty -- --all $ git clean -df $ git gc --agressive --prune=now

Slide 53

Slide 53 text

Recipes Modify Authorship # the precision option $ git filter-branch --env-filter ' if [ "$GIT_AUTHOR_NAME" = "Edmund Dantes" ]; then GIT_AUTHOR_NAME = "The Count of Monte Cristo"; GIT_AUTHOR_EMAIL = "[email protected]"; fi if [ "$GIT_COMMITTER_NAME" = "Edmund Dantes" ]; then GIT_COMMITTER_NAME = "Sinbad the Sailor"; GIT_COMMITTER_EMAIL = "[email protected]"; fi ' -- --all

Slide 54

Slide 54 text

Recipes Modify Authorship # the nuclear option $ git filter-branch --commit-filter ' if [ "$GIT_AUTHOR_NAME" = "Lila Crane" ]; then skip_commit "$@"; else git commit_tree "$@"; fi ' -- --all

Slide 55

Slide 55 text

Recipes Remove Large Files # find the largest files in your repo $ git verify-pack -v .git/objects/pack/pack-\*.idx | sort -k 3 -n # get the name of those files $ git rev-list --objects --all | grep $SHA # remove the file like we discussed earlier

Slide 56

Slide 56 text

Recipes Reformat Commit Messages # change your issue tracking system $ git filter-branch --msg-filter ' GIT_COMMIT = sed ’s/^#(\d{7})//g’ $GIT_COMMIT; PT_ID = $MY_SED_MATCH NEW_ID = id_conversion.txt | egrep "^$PT_ID" | cut -f 2 export GIT_COMMIT = "$GIT_COMMIT\n\nhttp://my_new_issue_tracker.com/ issue/$NEW_ID" ' -- --all