• Nebyly nalezeny žádné výsledky

Nástroje pro vývoj a

N/A
N/A
Protected

Academic year: 2022

Podíl "Nástroje pro vývoj a"

Copied!
28
0
0

Načítání.... (zobrazit plný text nyní)

Fulltext

(1)

Nástroje pro vývoj a monitorování software

GIT

Matematicko-fyzikální fakulta, Univerzita Karlova v Praze

Daniel Remiš

(2)

Overview

• Staging changes

– Commiting only selected changes

– C ommitting changes to one file in several phases – Describe output for `git diff` for a complex scenario

• Undo changes

• Branches and merging

– Basic concept

– Creating branches

– Switching working directory to another branch – Merging

– Resolving conflicts

(3)

File status lifecycle

(4)

Local operations

(5)

Track new file and check the status

$ git init

$ git add snake.pas

$ git status

# On branch master

# Initial commit

# Changes to be committed:

# (use "git rm --cached <file>..." to unstage)

#

# new file: snake.pas

#

$ git commit

git init Create an empty git repository.

git add Add file contents to the index.

git status Show the working tree status.

git commit Record changes to the repository.

(6)

Staged and unstaged file

If you modify a file after you run git add , you have to run git add again to stage the latest version of the file.

$ git status

# On branch master

# Changes to be committed:

# (use "git reset HEAD <file>..." to unstage)

#

# modified: snake.pas

#

# Changes not staged for commit:

# (use "git add <file>..." to update what will be committed)

# (use "git checkout -- <file>..." to discard changes in working directory)

#

# modified: snake.pas

#

(7)

View staged and unstaged changes

git diff Compares what is in your working directory with what is in your staging area.

git diff --cached Compares your staged changes to your last commit.

diff --git a/snake.pas b/snake.pas index 0e3b00a..d04c2fc 100644

--- a/snake.pas +++ b/snake.pas

@@ -1,3 +1,4 @@

+{my first game}

uses crt;

const a: byte = 2;

b: byte = 4;

(8)

Ignoring files and commit otions

.gitignore File, which disable tracking changes for files/folders.

git commit -v Puts the diff of your change in the editor.

git commit –m Type your commit message inline.

git commit –a Automatically stage every file

that is already tracked before

doing the commit.

(9)

Removing and moving files

git rm Remove files from the

working tree and from the index.

git rm –f Remove modified and indexed files.

git rm --cached Remove files from the index.

git mv Move or rename a file, a directory, or a symlink.

$ git mv default.html index.html

$ mv default.html index.html

$ git rm default.html

$ git add index.html

(10)

Undoing things

git commit --amend The commit you create replaces the current tip.

git reset HEAD <file> Unstaging a staged file.

git checkout -- <file> Unmodifying a modified file.

$ git commit -m 'initial commit'

$ git add index.html

$ git commit --amend

(11)

Branching and merging

git branch Create branch.

git branch -d Delete branch.

git checkout Checkout a branch or paths to the working tree.

git merge Join two or more development histories together.

$ git commit -m 'initial commit'

$ git add index.html

$ git commit --amend

(12)

Git vs. Subversion

Distributed version control diagram.

Centralized version control diagram.

(13)

Snapshots vs.Differences

data as snapshots

data as changes to a base

(14)

Comit

654fd.. 5dae1..

Snapshot A Snapshot B

commit

tree 4fde4f

author Dan..

commiter Dan..

commit

tree 43ea2f

author Dan..

commiter Dan..

parent 654fd

(15)

Branching

master

654ef5 56a3fe

Snapshot A Snapshot B

(16)

Branching 2

master

654ef5 56a3fe

pozdrav

$ git branch pozdrav

master HEAD

(17)

Branching 3

master

654ef5 56a3fe

pozdrav

$ git checkout pozdrav master

HEAD

(18)

Branching 4

master

654ef5 56a3fe

$ git commit –a –m „hello update“

master

HEAD 14a3fe

pozdrav

(19)

Branching 5

master

654ef5 56a3fe

$ git checkout master

master HEAD

14a3fe

pozdrav

(20)

Branching 6

master

56a3fe

$ git checkout –b rozlouceni

rozlouceni HEAD

14a3fe

pozdrav 654ef5

master master

(21)

Branching 7

master

56a3fe

$ git commit –a –m „added goodbye“

rozlouceni HEAD

14a3fe

pozdrav 654ef5

36fae master

master

(22)

Branching 8

master

56a3fe

$ git checkout master

rozlouceni HEAD

14a3fe

pozdrav 654ef5

36fae master

master

(23)

Branching 9

master

56a3fe

$ git merge rozlouceni

rozlouceni HEAD

14a3fe

pozdrav 654ef5

36fae master

master

(24)

Branching 10

master

56a3fe

$ git branch –d rozlouceni

HEAD

14a3fe

pozdrav 654ef5

36fae master

master

(25)

Merge conflict

master

56a3fe

$ git merge pozdrav

HEAD

14a3fe

pozdrav 654ef5

36fae master

master

(26)

Merge conflict 2

$ git merge pozdrav Auto-merging snake.pas

CONFLICT (content): Merge conflict in snake.pas

Automatic merge failed; fix conflicts and then commit the result.

$ git status

# On branch master

# You have unmerged paths.

# (fix conflicts and run "git commit")

#

# Unmerged paths:

# (use "git add <file>..." to mark resolution)

#

# both modified: snake.pas

#

(27)

Merge conflict 3

master

56a3fe

$ git add snake.pas

$ git commit

HEAD

14a3fe

pozdrav 654ef5

36fae master

master

26afe1

(28)

Zdroje

Otázky

http://git-scm.com/book http://git-scm.com/docs

???

Odkazy

Související dokumenty

Tunica submucosa- žlázky v jícnu a duodenu (Brunnerovy) plicae circulares tenkého střeva.

Theent er pr i s ehasanadv i s or yc ommi t t eec ompos eds ol el yofempl oy ees .I ti si nt endedt oens ur et he democ r at i cgov er nanc eoft hec ompany .Thec ommi t t eemeet

Kodex (2004), based on the interna- tional best practice, recommends formation of auditing and remuneration commit- a full and correct disclosure and cooperation with

We are looking for students who support our research group with a field experiment.. You would have to work some days in May, June, July,

Your return on investment equals the present value of your accumulated net benefits (gross benefits less ongoing costs) over a certain time period, divided by your initial

Genetic testing — For using or storing human cells or tissues for genetic testing, you must obtain informed consent (see section 2) of the donor on the genetic testing, and show

Create new branch B and switch to it Modify some files and commit them Switch back to the master branch Modify some files and then commit Merge your branch B into the master Delete

Make some changes to different files in the working copy for the main line, and commit immediately. Print differences between the main line and branch Merge branch safely into the