Title: Welcome to Code versioning using git
1Welcome toCode versioning using git
Per Zetterberg School of Electrical Engineering
2code versioning systems
CVS, SVN, git, . purpose Keep track of created
textfiles (e.g. C code). Versions. Helps merge
changes by multiple users. We will use git
distributed versioning system but we will
used in a centralized manner
3The central repository github.com
- https//github.com/pzett/eq2440_2015
- All the code, all the commits, everything.
- What is on github is the backuped official state
of the project.
4Git client git bash
Git GUI
Copy and paste text. Mark upper-left corner
(icon). From menu Edit-gtCopy
Edit-gtPaste
5Set up local repository (local copy)
From the git bash command line gtgit clone
https//github.com/pzett/eq2440_2015.git
eq2440_alice gtcd eq2440_alice gtgit config -local
user.email alice_at_kth.se gtgit config -local
user.name alice Import the project into
eclipse 1) File-gtImport-gtExisting Android Code
Into Workspace -gt Browse to blue_alice/FrameWork
and select it 2) Right click FrameWork Package
Explorer in eclipse -gt build path -gt source tab
-gtAdd folder - gt Mark External Src- gt OK OK
Reading http//toroid.org/ams/git-central-repo-
howto
6How we will work
Repository eq2440_2015
Alice Implements or changes file1.cpp and
file2.cpp Updates repository git add file1.cpp
file2.cpp git commit -m comment
Bob Implements or changes file1.hpp and
file2.hpp Updates repository git add file1.hpp
file2.hpp git commit -m comment
git push
git push
git pull
git pull
7Conflict resolution
- Alice and Bob have clean updated local
repositories. - Alice modifies her file1.cpp
- Bob modifies his file1.cpp
- Bob does
- git add file1.cpp
- git commit -m change initialization of i1
- git push
- Alice does
- git add file1.cpp
- git commit -m I changed initialization of i1
to 2 - git push
- Alice gets message
- error failed to push some refs to
'https//github.com/pzett/blue.git' - hint Updates were rejected because the remote
contains work that you do - .
- CONFLICT (content) Merge conflict in file1.cpp
- Automatic merge failed fix conflicts and then
commit the result.
8Conflict resolution continued
- Alice gt git pull
- Auto-merging FrameWork/src/se/kth/android/StudentC
ode/file2.txt - CONFLICT (content) Merge conflict in
FrameWork/src/se/kth/android/ - file2.txt
- Automatic merge failed fix conflicts and then
commit the result. - Alice opens file1.cpp
- ltltltltltltlt HEAD
- i12
-
- I11
- gtgtgtgtgtgtgt 55f223d4ab24ae40f19ae551d51205b69a23177e
- Alice and Bob discusses and finds that Alice was
right. - Alice removes Bobs code and pushes it.
- Alicegt git add file1.cpp
- Alicegt git commit -F .git/MERGE_MSG
- Alicegt git push
- Bobgt git pull
Alice's code
Bob's code
9Exercise 1 Little red riding hood
- git clone https//github.com/pzett/test.git
test_yourname - Create file with name riding_hood.txt
- Insert your text one section at a time.
- Push result after each added section.
- Look at previous slides.
- You can look at the progress on web site
- https//github.com/pzett/test
10Branching
C0
C2
C1
11Branching
C0
C2
C1
C3
12Branching
C0
C2
C1
C3
C4
13Branching commands
- gtgit branch new_idea
- gtgit branch
- master
- new_idea
- gt git checkout new_idea
- gt git push --set-upstream origin new_idea
Let there be a new branch in the Local repository
List available branches.
This is the branch we are currently on.
Switch to the new branch.
Create a corresponding branch in the repository.
14Merge without conflict
Some work done and added and commited and pushed
on both branches.
Merging in new_idea into master gtget checkout
master gtgit merge new_idea Updating
37fb5f2..663442c Fast-forward FrameWork/src/se/kt
h/android/StudentCode/test.txt 1 1 file
changed, 1 insertion()
gt git push
15Merge (with conflict)
Some work done and added and commited and pushed
on both branches.
Merging in new_idea into master gtgit checkout
master gtgit merge new_idea Auto-merging
FrameWork/src/se/kth/android/StudentCode/test.txt
CONFLICT (content) Merge conflict in
FrameWork/src/se/kth/androi Automatic merge
failed fix conflicts and then commit the result.
Open test.txt and manually edit it as you want
it. gt git add test.txt gt git commit -F
.git/MERGE_MSG gt git push
Generates default merge message.
16Merge with branch on repository
gtgit merge origin/new_idea Then proceed as the
previous branch
17Exercise 2 Little red riding hood
- Create a personal branch and push it to the
server. - Interpolate (i.e. add more text) to the places
marked in your version of riding_hood.txt push
each section to the server. - When all are done merge with the versions of the
other students and make a meaningful text.
18Warning dont use stash (generally)
- gtgit pull
- error Your local changes to the following files
would be overwritten by checkout - riding_hood.txt
- Please, commit your changes or stash them before
you can switch branches. - Aborting
- Instead you should do
- git add riding_hood.txt
- git commit m Meaningful message
- git push
- Then try git pull.