SlideShare a Scribd company logo
1 of 9
Download to read offline
Merge, Rebase and how to resolve
Conflicts
In this exercise you will learn how to combine the work done in different branches and how
to resolve the conflicts which can occur during that process.
Preparation
Follow exercise 2, “Develop a feature/bug fix” to create a commit on a feature branch based
on the remote tracking branch origin/master.
Create a Conflicting commit
You may skip this step if you have already created conflicting changes in the previous
exercises. This is the case if you touched exactly the same line of the same file in different
feature branches. If this is not the case please do the following:
● Create a new local branch based on the remote tracking branch “origin/master”
● Create the new branch from the History View :
○ Select the project, then click Show In > History
○ Click “Create Branch...” on the commit where origin/master points to
● Do a different change in the same class on the same line as in the other branch (e.g.
you may add a class MultiplyOperation and add a corresponding line to method
setupDefaultOperations in class Calculator) and commit this change.
Merge the feature branches
Now you would like to have both new features in the master branch. One possibility to
achieve that is to merge the branches into the master branch, one after the other. Later in
this exercise you will learn another way, rebasing.
Trigger the first merge from the history view
● Check out the branch master where you want to have the merged state, i.e. where
the merge commit will be created, either by double clicking in the Repositories View,
or by selecting Checkout in the History View, or by using Team > Switch to > master,
or using the Checkout button in the Git tool bar.
● In the History View, select Merge in the context menu of the addDivide branch.
This will merge the content of the addDivde branch into the master branch. Since
there was no work done on the master branch and addDivide points to a successor
commit of the commit in master there is not much to do.
● Git simply forwards the master branch to the same commit as the addDivide
branch.
● Inspect the result in the history view.
Merge the second branch
● In the History View, select Merge in the context menu of the branch which contains
the conflicting commit. This will merge the content of this branch into the master
branch. This time the merge operation ends with conflicts.
Resolving merge conflicts
If a merge generates conflicts the repository is in a special state. The conflicts have to be
resolved until normal work can go on.
You can find the conflicting files by the conflict decorator in the package explorer::
If there are many conflicts it’s easier to find them in the Git Staging View:
● If you open the conflicting file in an editor you will find the conflict markers there. You
can directly edit the file here.
● You may use the Merge tool to resolve the conflicts: Select Merge Tool on the
conflicting file in the Staging View or “Team > Merge Tool” in the package explorer.
● By default the merge tool will show the two versions being merged, you can also
choose to let git pre-merge the file content by setting “Preferences > Team > Git
> Merge Tool Content” to “Workspace (pre-merged by Git)”. In this case conflict
markers are shown in the left pane in the file content pre-merged by git
● Click “Copy Current Change from Right to Left”
to take over the current change from right to left
● or edit the left side until you are happy with the change and save the file
● Now stage these modifications in the staging view or click “Team > Add to Index” on
the file. This marks the conflict as resolved and adds the conflict resolution to the git
index to add the conflict resolution to the merge commit in the next step.
● Click “Commit” in the Staging View. Note that git generates a merge commit
message. Leave it as it is, but do not forget the Change-Id-line in the Staging View if
you want to push the change to Gerrit later.
Undo merging with Reset
After you have done a merge as described above assume that you do not want the merge
commit in your branch anymore. You can easily undo the merge with the Reset operation.
(The same can also be done if the merge is not finished but your repository is in state
“Conflicting” or “Merged”).
● Select Reset > Hard on the commit where the branch pointed to before you did the
first merge.
Rebase
Now do a rebase of the conflicting commit instead of a merge.
● In the History View, check out one of the feature branches
● In the History View, select Rebase on on the second feature branch (the first one is
checked out):
● The rebase stops because of the conflict and shows the following dialog:
● Click Ok to start the merge tool.
● Again use the Merge tool to resolve the conflicts. Again as shown above for merge
you can adjust setting “Merge tool content” to let git pre-merge the file content in the
preferences.
Edit the left side until you are happy with the change and save
● Now open the Git Staging View
● Move the conflicting file to the “Staged Changes” area to tell git that the conflict is
resolved. If there are no conflicting files anymore, the “Continue” button gets enable.
Click the “Continue” button. Note: rebase is continued by a different operation
(“Continue”) than merge (“Commit”) since rebase is a multi-step operation which may
raise conflicts multiple times if you you are not only rebasing a single but multiple
commits in one go.
● Now the version graph should look like this: Note that there is a reference
ORIG_HEAD pointing to the commit which was checked out before the rebase
operation. You may revert the rebase operation with reset as described above.
● Now you may want to move the master branch to the rebased commit
○ Check out the master branch
○ Select “Rebase On” on the rebased commit
Copyright © 2014 by C. Halstrick, E. Kempin, S. Lay, S. Zivkov

More Related Content

Viewers also liked

Git Tutorial EclipseCon France 2014 - Git Exercise 01 - installation and conf...
Git Tutorial EclipseCon France 2014 - Git Exercise 01 - installation and conf...Git Tutorial EclipseCon France 2014 - Git Exercise 01 - installation and conf...
Git Tutorial EclipseCon France 2014 - Git Exercise 01 - installation and conf...msohn
 
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 2 - fetch the latest state
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 2 - fetch the latest stateGit Tutorial EclipseCon France 2014 - Gerrit Exercise 2 - fetch the latest state
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 2 - fetch the latest statemsohn
 
Git missiontomars 2015-03-10
Git missiontomars 2015-03-10Git missiontomars 2015-03-10
Git missiontomars 2015-03-10msohn
 
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 9 - starting demo gerrit
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 9 - starting demo gerritGit Tutorial EclipseCon France 2014 - Gerrit Exercise 9 - starting demo gerrit
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 9 - starting demo gerritmsohn
 
Git Tutorial EclipseCon France 2014 - Git Exercise 07 - git blame
Git Tutorial EclipseCon France 2014 - Git Exercise 07 - git blameGit Tutorial EclipseCon France 2014 - Git Exercise 07 - git blame
Git Tutorial EclipseCon France 2014 - Git Exercise 07 - git blamemsohn
 
Git Tutorial EclipseCon France 2014 - Git Exercise 06 - interactive rebase
Git Tutorial EclipseCon France 2014 - Git Exercise 06 - interactive rebaseGit Tutorial EclipseCon France 2014 - Git Exercise 06 - interactive rebase
Git Tutorial EclipseCon France 2014 - Git Exercise 06 - interactive rebasemsohn
 
The Git Tutorial - EclipseCon 2012
The Git Tutorial - EclipseCon 2012The Git Tutorial - EclipseCon 2012
The Git Tutorial - EclipseCon 2012msohn
 
Git journey from mars to neon EclipseCon North America - 2016-03-08
Git journey from mars to neon   EclipseCon North America - 2016-03-08Git journey from mars to neon   EclipseCon North America - 2016-03-08
Git journey from mars to neon EclipseCon North America - 2016-03-08msohn
 
Effective Git - EclipseCon 2011 tutorial
Effective Git - EclipseCon 2011 tutorialEffective Git - EclipseCon 2011 tutorial
Effective Git - EclipseCon 2011 tutorialmsohn
 
Code Matters - Eclipse Hackers Git Guide - EclipseCon France 2014
Code Matters - Eclipse Hackers Git Guide - EclipseCon France 2014Code Matters - Eclipse Hackers Git Guide - EclipseCon France 2014
Code Matters - Eclipse Hackers Git Guide - EclipseCon France 2014msohn
 
News from EGit - Talk EclipseCon Europe 2014 - Ludwigsburg
News from EGit - Talk EclipseCon Europe 2014 - LudwigsburgNews from EGit - Talk EclipseCon Europe 2014 - Ludwigsburg
News from EGit - Talk EclipseCon Europe 2014 - Ludwigsburgmsohn
 
Git and Eclipse - Eclipse Helios DemoCamp Jena 2010
Git and Eclipse - Eclipse Helios DemoCamp Jena 2010Git and Eclipse - Eclipse Helios DemoCamp Jena 2010
Git and Eclipse - Eclipse Helios DemoCamp Jena 2010msohn
 
EclipseCon 2010 talk: Towards contributors heaven
EclipseCon 2010 talk: Towards contributors heavenEclipseCon 2010 talk: Towards contributors heaven
EclipseCon 2010 talk: Towards contributors heavenmsohn
 
Versioning large binary files with JGit, EGit and Gerrit
Versioning large binary files with JGit, EGit and GerritVersioning large binary files with JGit, EGit and Gerrit
Versioning large binary files with JGit, EGit and Gerritmsohn
 
Cool new stuff in JGit and EGit - Eclipse Democamp Munich 2013-06-12
Cool new stuff in JGit and EGit - Eclipse Democamp Munich 2013-06-12Cool new stuff in JGit and EGit - Eclipse Democamp Munich 2013-06-12
Cool new stuff in JGit and EGit - Eclipse Democamp Munich 2013-06-12msohn
 
Passé composé auxiliaire avoir
Passé composé auxiliaire avoirPassé composé auxiliaire avoir
Passé composé auxiliaire avoirantjosegarcia
 

Viewers also liked (19)

Git Tutorial EclipseCon France 2014 - Git Exercise 01 - installation and conf...
Git Tutorial EclipseCon France 2014 - Git Exercise 01 - installation and conf...Git Tutorial EclipseCon France 2014 - Git Exercise 01 - installation and conf...
Git Tutorial EclipseCon France 2014 - Git Exercise 01 - installation and conf...
 
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 2 - fetch the latest state
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 2 - fetch the latest stateGit Tutorial EclipseCon France 2014 - Gerrit Exercise 2 - fetch the latest state
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 2 - fetch the latest state
 
Git missiontomars 2015-03-10
Git missiontomars 2015-03-10Git missiontomars 2015-03-10
Git missiontomars 2015-03-10
 
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 9 - starting demo gerrit
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 9 - starting demo gerritGit Tutorial EclipseCon France 2014 - Gerrit Exercise 9 - starting demo gerrit
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 9 - starting demo gerrit
 
Git Tutorial EclipseCon France 2014 - Git Exercise 07 - git blame
Git Tutorial EclipseCon France 2014 - Git Exercise 07 - git blameGit Tutorial EclipseCon France 2014 - Git Exercise 07 - git blame
Git Tutorial EclipseCon France 2014 - Git Exercise 07 - git blame
 
Git Tutorial EclipseCon France 2014 - Git Exercise 06 - interactive rebase
Git Tutorial EclipseCon France 2014 - Git Exercise 06 - interactive rebaseGit Tutorial EclipseCon France 2014 - Git Exercise 06 - interactive rebase
Git Tutorial EclipseCon France 2014 - Git Exercise 06 - interactive rebase
 
The Git Tutorial - EclipseCon 2012
The Git Tutorial - EclipseCon 2012The Git Tutorial - EclipseCon 2012
The Git Tutorial - EclipseCon 2012
 
Git journey from mars to neon EclipseCon North America - 2016-03-08
Git journey from mars to neon   EclipseCon North America - 2016-03-08Git journey from mars to neon   EclipseCon North America - 2016-03-08
Git journey from mars to neon EclipseCon North America - 2016-03-08
 
Effective Git - EclipseCon 2011 tutorial
Effective Git - EclipseCon 2011 tutorialEffective Git - EclipseCon 2011 tutorial
Effective Git - EclipseCon 2011 tutorial
 
Code Matters - Eclipse Hackers Git Guide - EclipseCon France 2014
Code Matters - Eclipse Hackers Git Guide - EclipseCon France 2014Code Matters - Eclipse Hackers Git Guide - EclipseCon France 2014
Code Matters - Eclipse Hackers Git Guide - EclipseCon France 2014
 
News from EGit - Talk EclipseCon Europe 2014 - Ludwigsburg
News from EGit - Talk EclipseCon Europe 2014 - LudwigsburgNews from EGit - Talk EclipseCon Europe 2014 - Ludwigsburg
News from EGit - Talk EclipseCon Europe 2014 - Ludwigsburg
 
Git and Eclipse - Eclipse Helios DemoCamp Jena 2010
Git and Eclipse - Eclipse Helios DemoCamp Jena 2010Git and Eclipse - Eclipse Helios DemoCamp Jena 2010
Git and Eclipse - Eclipse Helios DemoCamp Jena 2010
 
EclipseCon 2010 talk: Towards contributors heaven
EclipseCon 2010 talk: Towards contributors heavenEclipseCon 2010 talk: Towards contributors heaven
EclipseCon 2010 talk: Towards contributors heaven
 
Versioning large binary files with JGit, EGit and Gerrit
Versioning large binary files with JGit, EGit and GerritVersioning large binary files with JGit, EGit and Gerrit
Versioning large binary files with JGit, EGit and Gerrit
 
Cool new stuff in JGit and EGit - Eclipse Democamp Munich 2013-06-12
Cool new stuff in JGit and EGit - Eclipse Democamp Munich 2013-06-12Cool new stuff in JGit and EGit - Eclipse Democamp Munich 2013-06-12
Cool new stuff in JGit and EGit - Eclipse Democamp Munich 2013-06-12
 
A, as ou à
A, as ou àA, as ou à
A, as ou à
 
Futur pierre
Futur pierreFutur pierre
Futur pierre
 
Ratatouille 2ºeso
Ratatouille      2ºesoRatatouille      2ºeso
Ratatouille 2ºeso
 
Passé composé auxiliaire avoir
Passé composé auxiliaire avoirPassé composé auxiliaire avoir
Passé composé auxiliaire avoir
 

Similar to Git Tutorial EclipseCon France 2014 - Git Exercise 04 - merging rebasing and resolving conflicts

Git Branching and Merging.pptx
Git Branching and Merging.pptxGit Branching and Merging.pptx
Git Branching and Merging.pptxtapanvyas11
 
Git tutorial git branches 20131206-Bryan
Git tutorial   git branches 20131206-BryanGit tutorial   git branches 20131206-Bryan
Git tutorial git branches 20131206-BryanLearningTech
 
Introducing Git and git flow
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow Sebin Benjamin
 
Git Tutorials Git vs GitHub.pptx
Git Tutorials Git vs GitHub.pptxGit Tutorials Git vs GitHub.pptx
Git Tutorials Git vs GitHub.pptxDevOps University
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced gitGerrit Wanderer
 
Patch File.pdf
Patch File.pdfPatch File.pdf
Patch File.pdfvilaylala
 
Git usage (Basics and workflow)
Git usage (Basics and workflow)Git usage (Basics and workflow)
Git usage (Basics and workflow)Yeasin Abedin
 
Technical Seminar Series: GIT Pull Requests Best Practices
Technical Seminar Series:  GIT Pull Requests Best PracticesTechnical Seminar Series:  GIT Pull Requests Best Practices
Technical Seminar Series: GIT Pull Requests Best PracticesSingsys Pte Ltd
 
Git tutorial
Git tutorialGit tutorial
Git tutorialmobaires
 
Checkitmobile - using Git for development
Checkitmobile - using Git for developmentCheckitmobile - using Git for development
Checkitmobile - using Git for developmentGerrit Wanderer
 
GIT Workflows
GIT Workflows GIT Workflows
GIT Workflows BraveBits
 
Git cheat sheet__grey
Git cheat sheet__greyGit cheat sheet__grey
Git cheat sheet__greyKing Hom
 

Similar to Git Tutorial EclipseCon France 2014 - Git Exercise 04 - merging rebasing and resolving conflicts (20)

Git Branching and Merging.pptx
Git Branching and Merging.pptxGit Branching and Merging.pptx
Git Branching and Merging.pptx
 
Git tutorial git branches 20131206-Bryan
Git tutorial   git branches 20131206-BryanGit tutorial   git branches 20131206-Bryan
Git tutorial git branches 20131206-Bryan
 
wdt_09.pptx
wdt_09.pptxwdt_09.pptx
wdt_09.pptx
 
E caregitpresentation
E caregitpresentationE caregitpresentation
E caregitpresentation
 
Introducing Git and git flow
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow
 
Mastering GIT
Mastering GITMastering GIT
Mastering GIT
 
Git Best Practices.pptx
Git Best Practices.pptxGit Best Practices.pptx
Git Best Practices.pptx
 
Git Tutorials Git vs GitHub.pptx
Git Tutorials Git vs GitHub.pptxGit Tutorials Git vs GitHub.pptx
Git Tutorials Git vs GitHub.pptx
 
GIT Rebasing and Merging
GIT Rebasing and MergingGIT Rebasing and Merging
GIT Rebasing and Merging
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced git
 
Github
GithubGithub
Github
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
GDSC Git event 2023.pptx
GDSC Git event 2023.pptxGDSC Git event 2023.pptx
GDSC Git event 2023.pptx
 
Patch File.pdf
Patch File.pdfPatch File.pdf
Patch File.pdf
 
Git usage (Basics and workflow)
Git usage (Basics and workflow)Git usage (Basics and workflow)
Git usage (Basics and workflow)
 
Technical Seminar Series: GIT Pull Requests Best Practices
Technical Seminar Series:  GIT Pull Requests Best PracticesTechnical Seminar Series:  GIT Pull Requests Best Practices
Technical Seminar Series: GIT Pull Requests Best Practices
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Checkitmobile - using Git for development
Checkitmobile - using Git for developmentCheckitmobile - using Git for development
Checkitmobile - using Git for development
 
GIT Workflows
GIT Workflows GIT Workflows
GIT Workflows
 
Git cheat sheet__grey
Git cheat sheet__greyGit cheat sheet__grey
Git cheat sheet__grey
 

More from msohn

Project Gardener - EclipseCon Europe - 2018-10-23
Project Gardener - EclipseCon Europe - 2018-10-23Project Gardener - EclipseCon Europe - 2018-10-23
Project Gardener - EclipseCon Europe - 2018-10-23msohn
 
News from Git in Eclipse - EclipseCon EU - 2016-10-26
News from Git in Eclipse - EclipseCon EU - 2016-10-26News from Git in Eclipse - EclipseCon EU - 2016-10-26
News from Git in Eclipse - EclipseCon EU - 2016-10-26msohn
 
News from Git in Eclipse - EclipseCon 2015 Europe
News from Git in Eclipse - EclipseCon 2015 EuropeNews from Git in Eclipse - EclipseCon 2015 Europe
News from Git in Eclipse - EclipseCon 2015 Europemsohn
 
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 6 - submit a change
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 6 - submit a changeGit Tutorial EclipseCon France 2014 - Gerrit Exercise 6 - submit a change
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 6 - submit a changemsohn
 
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 1 - configure for gerrit
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 1 - configure for gerritGit Tutorial EclipseCon France 2014 - Gerrit Exercise 1 - configure for gerrit
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 1 - configure for gerritmsohn
 
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 8 - view gerrit review ...
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 8 - view gerrit review ...Git Tutorial EclipseCon France 2014 - Gerrit Exercise 8 - view gerrit review ...
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 8 - view gerrit review ...msohn
 
Git Tutorial EclipseCon France 2014 - Git Exercise 05 - history view
Git Tutorial EclipseCon France 2014 - Git Exercise 05 - history viewGit Tutorial EclipseCon France 2014 - Git Exercise 05 - history view
Git Tutorial EclipseCon France 2014 - Git Exercise 05 - history viewmsohn
 
Interactive Rebase with EGit
Interactive Rebase with EGitInteractive Rebase with EGit
Interactive Rebase with EGitmsohn
 
EGit 3.0 and beyond
EGit 3.0 and beyondEGit 3.0 and beyond
EGit 3.0 and beyondmsohn
 
Large Scale Development with Git and Gerrit - EclipseCon Europe 2012
Large Scale Development with Git and Gerrit - EclipseCon Europe 2012Large Scale Development with Git and Gerrit - EclipseCon Europe 2012
Large Scale Development with Git and Gerrit - EclipseCon Europe 2012msohn
 
News from Git in Java Land
News from Git in Java LandNews from Git in Java Land
News from Git in Java Landmsohn
 
Eclipse Hackers Guide to the Git Universe - Eclipse democamp Vienna 2011-12-02
Eclipse Hackers Guide to the Git Universe - Eclipse democamp Vienna 2011-12-02Eclipse Hackers Guide to the Git Universe - Eclipse democamp Vienna 2011-12-02
Eclipse Hackers Guide to the Git Universe - Eclipse democamp Vienna 2011-12-02msohn
 

More from msohn (12)

Project Gardener - EclipseCon Europe - 2018-10-23
Project Gardener - EclipseCon Europe - 2018-10-23Project Gardener - EclipseCon Europe - 2018-10-23
Project Gardener - EclipseCon Europe - 2018-10-23
 
News from Git in Eclipse - EclipseCon EU - 2016-10-26
News from Git in Eclipse - EclipseCon EU - 2016-10-26News from Git in Eclipse - EclipseCon EU - 2016-10-26
News from Git in Eclipse - EclipseCon EU - 2016-10-26
 
News from Git in Eclipse - EclipseCon 2015 Europe
News from Git in Eclipse - EclipseCon 2015 EuropeNews from Git in Eclipse - EclipseCon 2015 Europe
News from Git in Eclipse - EclipseCon 2015 Europe
 
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 6 - submit a change
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 6 - submit a changeGit Tutorial EclipseCon France 2014 - Gerrit Exercise 6 - submit a change
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 6 - submit a change
 
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 1 - configure for gerrit
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 1 - configure for gerritGit Tutorial EclipseCon France 2014 - Gerrit Exercise 1 - configure for gerrit
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 1 - configure for gerrit
 
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 8 - view gerrit review ...
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 8 - view gerrit review ...Git Tutorial EclipseCon France 2014 - Gerrit Exercise 8 - view gerrit review ...
Git Tutorial EclipseCon France 2014 - Gerrit Exercise 8 - view gerrit review ...
 
Git Tutorial EclipseCon France 2014 - Git Exercise 05 - history view
Git Tutorial EclipseCon France 2014 - Git Exercise 05 - history viewGit Tutorial EclipseCon France 2014 - Git Exercise 05 - history view
Git Tutorial EclipseCon France 2014 - Git Exercise 05 - history view
 
Interactive Rebase with EGit
Interactive Rebase with EGitInteractive Rebase with EGit
Interactive Rebase with EGit
 
EGit 3.0 and beyond
EGit 3.0 and beyondEGit 3.0 and beyond
EGit 3.0 and beyond
 
Large Scale Development with Git and Gerrit - EclipseCon Europe 2012
Large Scale Development with Git and Gerrit - EclipseCon Europe 2012Large Scale Development with Git and Gerrit - EclipseCon Europe 2012
Large Scale Development with Git and Gerrit - EclipseCon Europe 2012
 
News from Git in Java Land
News from Git in Java LandNews from Git in Java Land
News from Git in Java Land
 
Eclipse Hackers Guide to the Git Universe - Eclipse democamp Vienna 2011-12-02
Eclipse Hackers Guide to the Git Universe - Eclipse democamp Vienna 2011-12-02Eclipse Hackers Guide to the Git Universe - Eclipse democamp Vienna 2011-12-02
Eclipse Hackers Guide to the Git Universe - Eclipse democamp Vienna 2011-12-02
 

Recently uploaded

Webinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptWebinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptkinjal48
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxAutus Cyber Tech
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageDista
 
Streamlining Your Application Builds with Cloud Native Buildpacks
Streamlining Your Application Builds  with Cloud Native BuildpacksStreamlining Your Application Builds  with Cloud Native Buildpacks
Streamlining Your Application Builds with Cloud Native BuildpacksVish Abrams
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...OnePlan Solutions
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsJaydeep Chhasatia
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesSoftwareMill
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLAlluxio, Inc.
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadIvo Andreev
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampVICTOR MAESTRE RAMIREZ
 
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.Sharon Liu
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIIvo Andreev
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxJoão Esperancinha
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesShyamsundar Das
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionsNirav Modi
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdfMeon Technology
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfTobias Schneck
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyRaymond Okyere-Forson
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmonyelliciumsolutionspun
 

Recently uploaded (20)

Webinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptWebinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.ppt
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptx
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
 
Streamlining Your Application Builds with Cloud Native Buildpacks
Streamlining Your Application Builds  with Cloud Native BuildpacksStreamlining Your Application Builds  with Cloud Native Buildpacks
Streamlining Your Application Builds with Cloud Native Buildpacks
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retries
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and Bad
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - Datacamp
 
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AI
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptx
 
Salesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptxSalesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptx
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security Challenges
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspections
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdf
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human Beauty
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
 

Git Tutorial EclipseCon France 2014 - Git Exercise 04 - merging rebasing and resolving conflicts

  • 1. Merge, Rebase and how to resolve Conflicts In this exercise you will learn how to combine the work done in different branches and how to resolve the conflicts which can occur during that process. Preparation Follow exercise 2, “Develop a feature/bug fix” to create a commit on a feature branch based on the remote tracking branch origin/master. Create a Conflicting commit You may skip this step if you have already created conflicting changes in the previous exercises. This is the case if you touched exactly the same line of the same file in different feature branches. If this is not the case please do the following: ● Create a new local branch based on the remote tracking branch “origin/master” ● Create the new branch from the History View : ○ Select the project, then click Show In > History ○ Click “Create Branch...” on the commit where origin/master points to ● Do a different change in the same class on the same line as in the other branch (e.g. you may add a class MultiplyOperation and add a corresponding line to method setupDefaultOperations in class Calculator) and commit this change.
  • 2. Merge the feature branches Now you would like to have both new features in the master branch. One possibility to achieve that is to merge the branches into the master branch, one after the other. Later in this exercise you will learn another way, rebasing. Trigger the first merge from the history view ● Check out the branch master where you want to have the merged state, i.e. where the merge commit will be created, either by double clicking in the Repositories View, or by selecting Checkout in the History View, or by using Team > Switch to > master, or using the Checkout button in the Git tool bar. ● In the History View, select Merge in the context menu of the addDivide branch. This will merge the content of the addDivde branch into the master branch. Since there was no work done on the master branch and addDivide points to a successor commit of the commit in master there is not much to do. ● Git simply forwards the master branch to the same commit as the addDivide branch. ● Inspect the result in the history view.
  • 3. Merge the second branch ● In the History View, select Merge in the context menu of the branch which contains the conflicting commit. This will merge the content of this branch into the master branch. This time the merge operation ends with conflicts. Resolving merge conflicts If a merge generates conflicts the repository is in a special state. The conflicts have to be resolved until normal work can go on. You can find the conflicting files by the conflict decorator in the package explorer:: If there are many conflicts it’s easier to find them in the Git Staging View: ● If you open the conflicting file in an editor you will find the conflict markers there. You can directly edit the file here.
  • 4. ● You may use the Merge tool to resolve the conflicts: Select Merge Tool on the conflicting file in the Staging View or “Team > Merge Tool” in the package explorer. ● By default the merge tool will show the two versions being merged, you can also choose to let git pre-merge the file content by setting “Preferences > Team > Git > Merge Tool Content” to “Workspace (pre-merged by Git)”. In this case conflict markers are shown in the left pane in the file content pre-merged by git ● Click “Copy Current Change from Right to Left” to take over the current change from right to left
  • 5. ● or edit the left side until you are happy with the change and save the file ● Now stage these modifications in the staging view or click “Team > Add to Index” on the file. This marks the conflict as resolved and adds the conflict resolution to the git index to add the conflict resolution to the merge commit in the next step. ● Click “Commit” in the Staging View. Note that git generates a merge commit message. Leave it as it is, but do not forget the Change-Id-line in the Staging View if you want to push the change to Gerrit later. Undo merging with Reset After you have done a merge as described above assume that you do not want the merge commit in your branch anymore. You can easily undo the merge with the Reset operation. (The same can also be done if the merge is not finished but your repository is in state “Conflicting” or “Merged”). ● Select Reset > Hard on the commit where the branch pointed to before you did the first merge.
  • 6. Rebase Now do a rebase of the conflicting commit instead of a merge. ● In the History View, check out one of the feature branches ● In the History View, select Rebase on on the second feature branch (the first one is checked out): ● The rebase stops because of the conflict and shows the following dialog:
  • 7. ● Click Ok to start the merge tool. ● Again use the Merge tool to resolve the conflicts. Again as shown above for merge you can adjust setting “Merge tool content” to let git pre-merge the file content in the preferences. Edit the left side until you are happy with the change and save
  • 8. ● Now open the Git Staging View ● Move the conflicting file to the “Staged Changes” area to tell git that the conflict is resolved. If there are no conflicting files anymore, the “Continue” button gets enable. Click the “Continue” button. Note: rebase is continued by a different operation (“Continue”) than merge (“Commit”) since rebase is a multi-step operation which may raise conflicts multiple times if you you are not only rebasing a single but multiple commits in one go.
  • 9. ● Now the version graph should look like this: Note that there is a reference ORIG_HEAD pointing to the commit which was checked out before the rebase operation. You may revert the rebase operation with reset as described above. ● Now you may want to move the master branch to the rebased commit ○ Check out the master branch ○ Select “Rebase On” on the rebased commit Copyright © 2014 by C. Halstrick, E. Kempin, S. Lay, S. Zivkov