33
Praktische Aspekte der Informatik Moritz Mühlhausen Prof. Marcus Magnor https://graphics.tu-bs.de/teaching/ss19/padi/

Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone / git pull Make changes:

  • Upload
    habao

  • View
    218

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Praktische Aspekte

der InformatikMoritz Mühlhausen

Prof. Marcus Magnor

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 2: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Software VersioningGit basics, workflow, and commands

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 3: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Further Reading

Warning!The following slides are meant to give you

a very superficial introduction.

If you want to learn more, have a look at:

http://git-scm.com

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 4: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Outline

What is versioning

Git Basics

Git Setup

Git Workflow

Git Branches

Git Config

Assignment

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 5: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

A simple file server

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 6: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Lock-modify-unlock

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 7: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Copy-modify-merge

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 8: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Copy-modify-merge

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 9: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Outline

What is versioning

Git Basics

Git Setup

Git Workflow

Git Branches

Git Config

Assignment

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 10: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Basics

• Benefits:

Global revision numbers

No serialization (parallel editing)

Offline editing

Merging works most of the time

• Drawbacks:

Requires a disciplined workflow and maintenance!

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 11: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Basics

Initial checkout, and regular update to the newest version:

git init / git clone <url> / git pull

Make changes:

git add <files> / git mv <src> <dst>

Examine your changes:

git status / git diff [file]

Possibly undo some changes:

git reset [file] / git checkout --<file>

Commit changes:

git commit / git push

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 12: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Outline

What is versioning

Git Basics

Git Setup

Git Workflow

Git Branches

Git Config

Assignment

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 13: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Setup

Start versioning with init command:

$ git init

Initialized empty Git repository in ...

Creates an empty git repository with no remote target

• Pure versioning, no backup function

Add remote targets with remote add command

$ git remote add <name> <url>

Now push/pull commands with target <name> will access the

given repository

• If it is a repository and you have access to it

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 14: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Setup

Clone an already existing repository the long way:

$ git init

$ git remote add origin <url>

$ git branch ––set-upstream-to=origin/master master

$ git pull

Or use the clone shortcut

$ git clone <url>

Creates a subfolder with the repository name and sets everything up

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 15: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Outline

What is versioning

Git Basics

Git Setup

Git Workflow

Git Branches

Git Config

Assignment

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 16: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Workflow

Always use the pull command to get the latest version:

$ git pull

Updating 7073847..a005fe8

Fast-forward

food/sandwich.h | 2 +-

food/sandwich.cpp | 6 +++++-

2 files changed, 6 insertions(+), 2 deletions(-)

For bug hunting it is useful to look at old revisions by adding

$ git checkout <commit>

$ git blame <file>

$ git bisect

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 17: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Workflow

Check the status of all local files compared to the repository:

$ git status

Changes to be committed:

modified: food/sandwich.h

Changes not staged for commit:

modified: food/sandwich.cpp

Untracked files:

food/food.txt

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 18: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Workflow

$ git diff

index: 05f23b8..800e28a 100644

--- a/food/sandwich.cpp

+++ b/food/sandwich.cpp

@@ -1,5 +1,9 @@

#include "sandwich.h"

+#include <sys/types.h>

+#include <sys/stat.h>

+#include <unistd.h>

+#include <stdio.h>

int main(void) {

- printf("Sixty-four slices of American Cheese...\n");

+ printf("Sixty-five slices of American Cheese...\n");

}

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 19: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Workflow

If there is a conflict, all relevant versions are still available in their

respective commit:

$ git pull

From http://git.cg.cs.tu-bs.de:6000/PADI/test

fbb93f8..f82df1b master -> origin/master

Auto-merging food/food.txt

CONFLICT (content): Merge conflict in food/food.txt

Automatic merge failed; fix conflicts and then commit the

result

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 20: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Workflow

$ cat sandwich.txt

Top piece of bread

Mayonnaise

Lettuce

Tomato

Provolone

<<<<<<< HEAD

Salami

Mortadella

Prosciutto

=======

Sauerkraut

Grilled Chicken

>>>>>>> f82df1b22544bf943520a7669991f88b443fa81d

Creole Mustard

Bottom piece of bread

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 21: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Workflow

You can manually merge those files:

• In editor by hand, remove the <<<, ===, >>> lines and merge them to

your desire

• Use $ git mergetool food/food.txt

You can avoid them beforehand:

$ git pull –s ours sandwich.txt

Always prefer your file over the current revision.

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 22: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Workflow

You can then commit your merge:

$ git commit -a

Merge branch ‘master’ of http://git.cg.cs.tu-bs.de:6000/PADI/test

# Conflicts:

# food/food.txt

#

# It looks like you may be committing a merge.

# If this is not correct, please remove the file

# .git/MERGE_HEAD

# and try again

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 23: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Things to watch out for

• Commit often

• Always use understandable messages

• Only commit code that compiles

• Avoid conflicts early, by designating responsibilities.

• Do not commit temporary files!

• Do not commit ‘backup’ files!

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 24: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Outline

What is versioning

Git Basics

Git Setup

Git Workflow

Git Branches

Git Config

Assignment

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 25: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Branches

A branch refers to a separate development line in your git

repository

• Work on a specific taks without messing the main line

• Easy switching in between

A single branch log example:

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 26: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Branches

Now you want to test something but don’t mess with the master

code

• Create a new branch

• Work on that branch and merge it later

A two branch log example:

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 27: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Branches

Create a branch / delete a branch

$ git branch <name> / git branch –d <name>

Switch to a different branch

$ git checkout <name>

Merge a branch into the current branch

$ git merge <name>

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 28: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Outline

What is versioning

Git Basics

Git Setup

Git Workflow

Git Branches

Git Config

Assignment

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 29: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Config

Customize your git with several configuration options

$ git config <key> <setting>

Sets a config locally for this repository

For global options add --global

$ git config –-global <key> <setting>

Sets the global config which will be used if no local option is set

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 30: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Config – First time git setup

Some options should be set globally once for each computer

Set your identity – important because git commit uses these

information

$ git config -–global user.name “<your_name>”

$ git config –-global user.email “<your_email>”

Set the editor for commit messages

$ git config –-global core.editor <editor>

If not set it uses the shell environment variables VISUAL or EDITOR

Otherwise it uses vi

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 31: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Git Config – Our git problems

Unfortunately, our git certificate is self signed, so git is quite

unhappy

$ git config http.sslVerify false

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 32: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Outline

What is versioning

Git Basics

Git Setup

Git Workflow

Git Branches

Git Config

Assignment

https://graphics.tu-bs.de/teaching/ss19/padi/

Page 33: Praktische Aspekte der Informatik - graphics.tu-bs.de · Git Basics Initial checkout, and regular update to the newest version: git init / git clone  / git pull Make changes:

Assignment

A. Get a git account on our server

Get your account information from me.

Go to the website: git.cg.cs.tu-bs.de

Check your account.

B. Add a SSH key to your accountOptional: Create a new ssh key for your computerssh-keygen -t rsa -b 4096 -C "[email protected]

Go to your settings -> SSH Keys

Add your key.

https://graphics.tu-bs.de/teaching/ss19/padi/