Better Commit than Sorry https://xkcd.com/1597/ What is and why - - PowerPoint PPT Presentation

better commit than sorry
SMART_READER_LITE
LIVE PREVIEW

Better Commit than Sorry https://xkcd.com/1597/ What is and why - - PowerPoint PPT Presentation

Better Commit than Sorry https://xkcd.com/1597/ What is and why should we use it? DVCS - distributed version control system allows lots of people to work together tracks file version in a shared history assists in the


slide-1
SLIDE 1

Better Commit than Sorry

https://xkcd.com/1597/

slide-2
SLIDE 2

What is

and why should we use it?

  • DVCS - distributed version control system
  • allows lots of people to work together
  • tracks file version in a shared history
  • assists in the development process

https://i.stack.imgur.com/yof9f.png

slide-3
SLIDE 3

GIT The Basics

  • config
  • managing files
  • behind the curtain
slide-4
SLIDE 4

git config (--global | --system)

  • /etc/gitconfig

| system wide

  • ~/.gitconfig

| user wide

  • .git/config

| project wide

  • user.name “Florian Sattler”
  • user.email “sattlerf@fim.uni-passau.de”
  • alias.fancyLog “log --color --graph”

git config --list

slide-5
SLIDE 5

file status

https://git-scm.com/images/about/index1@2x.png

slide-6
SLIDE 6

git diff | changed and not staged git diff --staged | compares staged with last commit

untracked unmodified modified staged git add edit git add git commit git rm --cached git reset git reset git checkout file status

slide-7
SLIDE 7

git commit tree: 4bbc25 blob: aa43aa tree: 78ba8a blob: aa43aa {file content} tree: 78ba8a blob: 2d5edf blob: 30d77f blob: 2d5edf {file content} blob: 30d77f {file content} commit: 149fbd tree: 4bbc25 parent: 8869e2 author: Florian committer: Florian message: {new stuff} git cat-file -p {hash}

slide-8
SLIDE 8

The history commit: 37a921 tree: fe8e13 parent: 151c57 author: Mr Bug committer: Mr Crless message: {la di da} commit: 8869e2 tree: deb987 parent: 37a921 author: Mr Fix committer: Mr Fix message: {fixed foo} commit: 149fbd tree: 4bbc25 parent: 8869e2 author: Florian committer: Florian message: {new stuff} commit: 149fbd tree: 4bbc25 parent: 8869e2 author: Florian committer: Florian message: {new stuff} snapshot snapshot snapshot

slide-9
SLIDE 9
slide-10
SLIDE 10

Many commits, know handle it!!!

  • braches
  • remote interaction
  • merging
  • rebase
slide-11
SLIDE 11

Branches commit: 37a921 commit: 8869e2 commit: 149fbd master testing HEAD commit: 809d82 testing git branch testing | create branch named testing HEAD HEAD git checkout testing | switch HEAD to testing branch pointer current branch

slide-12
SLIDE 12

Merging commit: 37a921 commit: 8869e2 commit: 149fbd master commit: 809d82 testing HEAD commit: 877f43 master HEAD

slide-13
SLIDE 13

Merging commit: 8869e2 commit: 149fbd commit: 809d82 testing git merge testing | merge branch testing into master commit: 877f43 master HEAD commit: 8390ab master HEAD merge commit

slide-14
SLIDE 14

remote interaction

  • git remote

  • v

| show URLs ○ add [r-name] [url] | add new remote ○ show [r-name] | shows infos of remote ○ rm [r-name] | remove remote ○ rename [r-old] [r-new] | local rename name of the remote

  • rigin ssh://gitblit/~vulder/foo.git (fetch)
  • rigin ssh://gitblit/~vulder/foo.git (push)

github git@github.com:vulder/foo.git (fetch) github git@github.com:vulder/foo.git (push)

  • git fetch [r-name]

| gets objects/refs from remote

  • git pull

| gets o/r from remote and merges them into own

  • git push [r-name] [branch]

| pushes local o/r to remote

slide-15
SLIDE 15

commit: 8869e2 commit: 149fbd commit: 809d82 commit: 877f43 master HEAD

  • rigin/master

testing

  • rigin/testing

HEAD testing

  • rigin/master

git push | push current branch to remote

  • rigin/testing

remote branches

slide-16
SLIDE 16

commit: 8869e2 commit: 149fbd commit: 809d82 commit: 877f43 master HEAD testing

  • rigin/master

git pull | get changes from origin

  • rigin/testing

master git checkout master | switch to brache master HEAD git merge testing | merge testing into master commit: 8390ab merge commit master HEAD merge conflict

slide-17
SLIDE 17

http://www.columbia.edu/~zjn2101/intermediate-git/meme-merge.jpg

slide-18
SLIDE 18

resolving conflicts (git merge testing) master testing git mergetool -t diffuse git commit

slide-19
SLIDE 19

3-way merge commit: 8869e2 commit: 149fbd commit: 809d82 commit: 877f43 commit: 8390ab master HEAD testing LOCAL REMOTE BASE git config merge.conflictStyle diff3

slide-20
SLIDE 20

when git turns into guitar hero

https://i.kinja-img.com/gawker-media/image/upload/hvkhczj1c4qqn5edap0e.jpg https://pbs.twimg.com/media/CaI8xA3W0AA6wMe.png

slide-21
SLIDE 21

rebase c1 c2 c3 c5 c6 c4 c7 c9 c8 c2 git rebase master master testing c4 c7 c9 testing

slide-22
SLIDE 22

rebase II c1 c2 c3 c5 c6 c4 c7 c9 c8 c2 master testing c10 c11 feature git rebase --onto master testing feature c10 c11 feature

slide-23
SLIDE 23

rebase III c1 c2 c3 c5 c6 c4 c7 c9 c8 c2 master testing c10 c11 c7 c9 git rebase --onto testing~4 testing~2 testing

slide-24
SLIDE 24

rebase III c1 c2 c3 c5 c6 c4 c7 c9 c8 c2 master testing c10 c11 c7 c9 git rebase --onto testing~4 testing~2 testing

slide-25
SLIDE 25

rebase III c1 c2 c3 c5 c6 c4 c8 c2 master testing c10’ c11’ git rebase --onto testing~4 testing~2 testing c12 c13

slide-26
SLIDE 26

rebase interactive git rebase -i master~3 master

slide-27
SLIDE 27

https://imgur.com/XFQLB https://imgur.com/c4jt321

slide-28
SLIDE 28

rebase problem c1 c2 c3 c5 c6 c4 c8 c2 master testing c10 c11 c12 c13 cXX cXY remote dev git config pull.rebase true

slide-29
SLIDE 29
slide-30
SLIDE 30

git reflog logs the states where branches/HEAD was before a change occurred git reset --hard c38d994 repo state before “reset --hard HEAD~”

slide-31
SLIDE 31

Let’s work with

  • thers
  • tags
  • workflows
  • finding bugs
  • more useful commands
slide-32
SLIDE 32

tags (git tag) lightweight tag: git tag [new tag name] annotated tag: git tag -a [tag] -m [message] + sign tag with -s default email key Conf: user.signingKey = [keyid] git push [remote] [tag-name]

slide-33
SLIDE 33

github - GPG support

slide-34
SLIDE 34

git request-pull git request-pull <start> <url> [<end>] git request-pull origin/master git@github.com:vulder/foo.git

slide-35
SLIDE 35

centralized workflow central repository server/github John Eve Smith

slide-36
SLIDE 36

integration-manager workflow blessed repository John Eve John public repo Eve public repo Smith integration manager

slide-37
SLIDE 37

dictator and lieutenants workflow blessed repository John public repo Eve public repo Smith dictator Lieutenant II Lieutenant I

slide-38
SLIDE 38

git flow (https://github.com/nvie/gitflow)

  • master
  • develop
  • feature
  • release
  • hotfix

nvie.com

slide-39
SLIDE 39
slide-40
SLIDE 40

git bisect c1 c2 c3 c2 c4 c5 c6 c7 c8 c9 master HEAD

bad good bad bad good

slide-41
SLIDE 41

git blame {file} tool: tig

slide-42
SLIDE 42
slide-43
SLIDE 43

git cherry-pick apply changes from existing commit c1 c2 c3 c5 c6 c4 c7 c6’ c8 c9 c6 git cherry-pick c6

  • n

| no commit

  • e

| edit

  • x

| add from line c2

slide-44
SLIDE 44

git revert reverte existing commit c1 c2 c3 c5 c6 c4 c7 c6’ c8 c9 c6 c2 git revert c7

  • c7

c10 git revert -n master~5..master~2

  • n

| no commit

  • e

| edit

slide-45
SLIDE 45

hooks (.git/hooks)

  • pre-commit

| invoked by git commit

  • commit-msg

| invoked by git commit

  • pre-push

| invoked by git push

  • pre-receive/update

| invoked by git-receive-pack

slide-46
SLIDE 46

Tools, Tools, Tools

  • big files
  • tig
  • git GUI
  • handling .docx
slide-47
SLIDE 47

tooling

  • gitk
  • tig
  • sourcetree
  • git-cola
slide-48
SLIDE 48

tooling

  • gitk
  • tig
  • sourcetree
  • git-cola
  • docx to text

gitattributes .git/info/attributes | path/file spec settings | word filter | script to call docx converter git config diff.word.textconv docx2txt *.docx diff=word infos @ https://git-scm.com/book/uz/v2/Customizing-Git-Git-Attributes @ http://docx2txt.sourceforge.net/

1. #!/bin/bash 2. docx2txt.pl $1 -

slide-49
SLIDE 49
  • ther stuff
  • git clean
  • git grep
  • read-tree + subtree
  • git replace
  • git fsck
  • git bundle
  • git log -L
  • git describe
  • git archive
  • git rerere
  • git submodules

...

slide-50
SLIDE 50