A Brief Introduction to Working with Git
-
Upload
philip-langer -
Category
Technology
-
view
319 -
download
1
description
Transcript of A Brief Introduction to Working with Git
![Page 1: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/1.jpg)
Business Informatics GroupInstitute of Software Technology and Interactive Systems Vienna University of TechnologyFavoritenstraße 9-11/188-3, 1040 Vienna, Austriaphone: +43 (1) 58801-18804 (secretary), fax: +43 (1) [email protected], www.big.tuwien.ac.at
A Brief Introduction to Working with Git
10.03.2014VUT, Vienna, Austria
Philip Langer
![Page 2: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/2.jpg)
History of Versioning Systems
Based on http://codicesoftware.blogspot.com/2010/11/version-control-timeline.html
local to central …
central to distributed …
1972
sccsdiscourage branching … everything is a branch …
![Page 3: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/3.jpg)
3
Git: A Distributed Versioning System
There is no single repository server Every peer is a full repository instance
Single-peer versioning possible Including the complete history Committing changes is independent of peers Allows disconnected operation
Collaboration is done by pushing/pulling commits Comparable to peer-to-peer networks The role of peers is purely organizational
No technical difference among peers Single common central server possible
One peer happens to be the central repo But several other architectures are possible too
Gate-keeper architecture Teams of teams
commit
push & pull
push & pull
push & pull
<Bob>
<Alice>
<Sally>
<Server>
<Harry>
push & pull
![Page 4: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/4.jpg)
4
The Four Layers & Transferring Changes Among Them
Every repository consists of a Workspace Index (“staging area”) Local repository Remote repositories …
Transferring changes git add
workspace to index git commit
index to local branch git push
local branch to remote branch …
Changes are organized in commits Each commit has a parent The history is basically a DAG
![Page 5: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/5.jpg)
5
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is HEAD? A reference pointing to the last commit (of the current branch) Thus, it will be the parent of the next commit Relative commit expressions e.g. with HEAD~2
git reset [--soft | --mixed | --hard] [commit | reference to commit] Resets HEAD in history, index, and/or workspace to [commit] git reset --hard
History, index, and workspace git reset [--mixed]
History and index git reset --soft
Only history …
default:HEAD
default:--mixed
History
Index
Workspace
Head
![Page 6: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/6.jpg)
6
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is HEAD? A reference pointing to the last commit (of the current branch) Thus, it will be the parent of the next commit Relative commit expressions e.g. with HEAD~2
git reset [--soft | --mixed | --hard] [commit | reference to commit] Resets HEAD in history, index, and/or workspace to [commit] git reset --hard
History, index, and workspace git reset [--mixed]
History and index git reset --soft
Only history …
default:HEAD
default:--mixed
History
Index
Workspace
Head
![Page 7: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/7.jpg)
7
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is HEAD? A reference pointing to the last commit (of the current branch) Thus, it will be the parent of the next commit Relative commit expressions e.g. with HEAD~2
git reset [--soft | --mixed | --hard] [commit | reference to commit] Resets HEAD in history, index, and/or workspace to [commit] git reset --hard
History, index, and workspace git reset [--mixed]
History and index git reset --soft
Only history …
default:HEAD
default:--mixed
History
Index
Workspace
Head
![Page 8: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/8.jpg)
8
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is HEAD? A reference pointing to the last commit (of the current branch) Thus, it will be the parent of the next commit Relative commit expressions e.g. with HEAD~2
git reset [--soft | --mixed | --hard] [commit | reference to commit] Resets HEAD in history, index, and/or workspace to [commit] git reset --hard HEAD~
History, index, and workspace git reset [--mixed]
History and index git reset --soft
Only history …
default:HEAD
default:--mixed
History
Index
Workspace
Head
![Page 9: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/9.jpg)
9
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is HEAD? A reference pointing to the last commit (of the current branch) Thus, it will be the parent of the next commit Relative commit expressions e.g. with HEAD~2
git reset [--soft | --mixed | --hard] [commit | reference to commit] Resets HEAD in history, index, and/or workspace to [commit] git reset --hard HEAD~
History, index, and workspace git reset [--mixed]
History and index git reset --soft
Only history …
default:HEAD
default:--mixed
History
Index
Workspace
Head
!
![Page 10: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/10.jpg)
10
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is HEAD? A reference pointing to the last commit (of the current branch) Thus, it will be the parent of the next commit Relative commit expressions e.g. with HEAD~2
git reset [--soft | --mixed | --hard] [commit | reference to commit] Resets HEAD in history, index, and/or workspace to [commit] git reset --hard
History, index, and workspace git reset [--mixed]
History and index git reset --soft
Only history …
default:HEAD
default:--mixed
History
Index
Workspace
Head
![Page 11: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/11.jpg)
11
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is HEAD? A reference pointing to the last commit (of the current branch) Thus, it will be the parent of the next commit Relative commit expressions e.g. with HEAD~2
git reset [--soft | --mixed | --hard] [commit | reference to commit] Resets HEAD in history, index, and/or workspace to [commit] git reset --hard
History, index, and workspace git reset [--mixed]
History and index git reset --soft
Only history …
default:HEAD
default:--mixed
History
Index
Workspace
Head
Reset index after wrong
add
![Page 12: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/12.jpg)
12
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is HEAD? A reference pointing to the last commit (of the current branch) Thus, it will be the parent of the next commit Relative commit expressions e.g. with HEAD~2
git reset [--soft | --mixed | --hard] [commit | reference to commit] Resets HEAD in history, index, and/or workspace to [commit] git reset --hard
History, index, and workspace git reset [--mixed] HEAD~
History and index git reset --soft
Only history …
default:HEAD
default:--mixed
History
Index
Workspace
Head
![Page 13: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/13.jpg)
13
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is HEAD? A reference pointing to the last commit (of the current branch) Thus, it will be the parent of the next commit Relative commit expressions e.g. with HEAD~2
git reset [--soft | --mixed | --hard] [commit | reference to commit] Resets HEAD in history, index, and/or workspace to [commit] git reset --hard
History, index, and workspace git reset [--mixed] HEAD~
History and index git reset --soft
Only history …
default:HEAD
default:--mixed
History
Index
Workspace
Head
Undo last commit, however
it‘s still there
![Page 14: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/14.jpg)
14
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is HEAD? A reference pointing to the last commit (of the current branch) Thus, it will be the parent of the next commit Relative commit expressions e.g. with HEAD~2
git reset [--soft | --mixed | --hard] [commit | reference to commit] Resets HEAD in history, index, and/or workspace to [commit] git reset --hard
History, index, and workspace git reset [--mixed]
History and index git reset --soft
Only history …
default:HEAD
default:--mixed
History
Index
Workspace
Head
Does nothing actualy
(HEAD is default)
![Page 15: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/15.jpg)
15
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is HEAD? A reference pointing to the last commit (of the current branch) Thus, it will be the parent of the next commit Relative commit expressions e.g. with HEAD~2
git reset [--soft | --mixed | --hard] [commit | reference to commit] Resets HEAD in history, index, and/or workspace to [commit] git reset --hard
History, index, and workspace git reset [--mixed]
History and index git reset --soft HEAD~
Only history …
default:HEAD
default:--mixed
History
Index
Workspace
Head
![Page 16: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/16.jpg)
16
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is HEAD? A reference pointing to the last commit (of the current branch) Thus, it will be the parent of the next commit Relative commit expressions e.g. with HEAD~2
git reset [--soft | --mixed | --hard] [commit | reference to commit] Resets HEAD in history, index, and/or workspace to [commit] git reset --hard
History, index, and workspace git reset [--mixed]
History and index git reset --soft HEAD~
Only history …
default:HEAD
default:--mixed
History
Index
Workspace
Head
Undo last commit, leaving index untouched
![Page 17: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/17.jpg)
17
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is checkout? Get a version from the history And overwrite workspace (also for creating and changing branches … later)
git checkout -- <file/s> Get version of <file/s> from HEAD Overwrite version in workspace
History
Index
Workspace
Head
Undo last commit, leaving index untouched
![Page 18: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/18.jpg)
18
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is checkout? Get a version from the history And overwrite workspace (also for creating and changing branches … later)
git checkout -- <file/s> Get version of <file/s> from HEAD Overwrite version in workspace
History
Index
Workspace
Head
Undo local changes to workspace.
!
![Page 19: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/19.jpg)
19
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is revert? Does not modify history (good if you pushed already) Takes a commit from history Creates reverse patch Commits reverse patch (new commit)
git revert HEAD~1
History
Index
Workspace
Head
Must be clean!
![Page 20: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/20.jpg)
20
Before talking about branches…Demystifying “git reset”, “git checkout”, and “git revert”
What is revert? Does not modify history (good if you pushed already) Takes a commit from history Creates reverse patch Commits reverse patch (new commit)
git revert HEAD~1
History
Index
Workspace
Head
Undo commits after you‘ve already pushed them.
Must be clean!
![Page 21: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/21.jpg)
21
Branching
After all every change (local or remote) is a fork leading to a new branch So make branches a first-class concept No logical difference between local and remote branches Every merge is a branch merge
<Bob>
<Server>
<Alice>
![Page 22: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/22.jpg)
22
Branching
Each commit has a parent A branch is nothing more than a pointer to a commit
CurrentBranch
![Page 23: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/23.jpg)
23
Branching
Each commit has a parent ( DAG) A branch is nothing more than a pointer to a commit
![Page 24: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/24.jpg)
24
Branching
Local branches may link to “tracking branches”
CurrentBranch
![Page 25: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/25.jpg)
25
Branching
Branches can be linked in ./git/config(links are also created automatically in certain cases;or may be linked explicitly using git checkout --track)
[remote "origin"]fetch = +refs/heads/*:refs/remotes/origin/*url = https://code.google.com/a/eclipselabs.org/p/moliz/
[branch "master"]remote = originmerge = refs/heads/master
[branch "issue_18_alf"]remote = originmerge = refs/heads/issue_18_alf
![Page 26: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/26.jpg)
26
Merging Branches
git checkout mastergit merge iss53
![Page 27: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/27.jpg)
27
Merging Branches
git checkout mastergit merge iss53
Note that git pull is a git fetch & git merge
![Page 28: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/28.jpg)
28
Branching Models of Git
Several different “models” All entirely organizational
The svn-like model: Only one branch Only one central repo git pull (origin master) Apply changes git commit (master) git push (origin master) Good for e.g. papers
The isolated-development model Own branch for current dev Own branch for releases Own branch for each feature
![Page 29: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/29.jpg)
29
Keeping the History of Topic Branches Clean: Rebase
git checkout experiment… // apply changesgit commit -agit checkout mastergit merge experiment
![Page 30: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/30.jpg)
30
Keeping the History of Topic Branches Clean: Rebase
git checkout experiment… // apply changesgit commit -agit checkout mastergit merge experiment
![Page 31: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/31.jpg)
31
Keeping the History of Topic Branches Clean: Rebase
git checkout experiment… // apply changesgit commit -agit rebase master
Rebase is rewriting history! Never rebase pushed history!
![Page 32: A Brief Introduction to Working with Git](https://reader033.fdocuments.in/reader033/viewer/2022061112/5456b6eaaf795998788b4eb7/html5/thumbnails/32.jpg)
32
Keeping the History of Topic Branches Clean: Rebase
Improving previous commits… // apply changesgit commit -a… // apply changesgit commit -agit rebase -i HEAD~2
# Rebase 710f0f8..a5f4a0d onto 710f0f8## Commands:# p, pick = use commit# e, edit = use commit, but stop for amending# s, squash = use commit, but meld into previous commit