0% found this document useful (0 votes)
76 views49 pages

Git Tutorial

Book

Uploaded by

Vasanth Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views49 pages

Git Tutorial

Book

Uploaded by

Vasanth Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

GitTutorialTour

JonLoeliger

TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

GitTutorialTourOutline

RepositoryManagement
GitRepositoryConcepts
InterRepositoryDataFlow
Branches
Merges
LocalUseCases
PullUpdates
GeneratingPatches
Examples
SupplementalSlides
Slide2
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

GitConcepts:Repositories

Gitrepositoryisselfcontained,localandcomplete
Doesn'trequireexternalcontent
Nocentralizedrepository
Includescompletehistoryofeveryfileandchangelog

Gitrepositoryisnotdistributed

No:parthere,partthere,partoverthere...

Nogitrepositoryisinherentlyauthoritative

Onlyauthoritativebyconventionandagreement

Slide3
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

GitConcepts:DistributedDevelopment

Developmentcanbedistributed

Multiplerepositoriescancreatedifferenthistoriesandchanges

Eveniftheyoriginatedfromacommonancestor

Multiplerepositorieswithdifferentdevelopmentcanbecombined

Developmentcanbeshared

Multipledeveloperscanuseandupdateacommonrepository

Nomatteriftherepositoryislocalorremote

Developmentcanbeprivate

RevisioncontrolyourAddressListathome

Slide4
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

RepositoryNetwork
torvalds
someos-2.6

jgarzik
netdev

paulus
sometree

perex
alsa
herbert
crypto
Susan

Bob

galak
85xx

Chris

Eric
Kim

Anne
Brandi
Fnord
A

Slide5
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

B is cloned from A

RepositoryDataFlow
Downstream

Upstream

Colors indicate
action instigator

Linus
someos-2.6

pull

push

pull

pull

patches
push

pull

patches
push

Mackerras
sometree

push

pull

Susan

Slide6
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

patches
push

GitConcepts:Branchesingit

Cheap,fastandeasy
Topic/DevelopmentBranches

Stable,development,bugfix,testingbranches
Smalldevelopmentlines,perfeature,perdeveloper,etc
Collect,reorderororganizechanges
Cherrypickparticularpatches

TrackingBranches

Followupstreamchangesinlocalrepository
Don'tcommittotrackingbranches
IdentifiedasRHSofPull:refspecs

BranchnamesrefertothecurrentbranchHEADrevision
Branchesdon'thaveabeginningperse
$ git merge-base <original-branch> <branch-name>

Slide7
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

Branches:Cloning

ClonefromupstreamURL

Original Repository

$ git clone
git://www.jdl.com/software/dtc.git

master

Copiescompleteupstreamrepositoryinto
alocalrepository

git clone

Createsorigintrackingbranch

Tracksupstreammasterbranch

ClonedRepository

Introducesmasterdevelopmentbranch
Initiallythesameplaceasorigin
Foryourdevelopment
Slide8
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

origin

master

Branches:CommitOntoBranches

Masterbranchinyourrepoisforyourdevelopment!
$ git checkout master
# Edit a file.
$ git commit -a -m "Add copyright.

Fix 80-column line."

Introduceyourowntopicdevelopmentbranchestoo
$ git checkout -b jdl
# Edit a file.
$ git commit -a -m "Remove dead code."

Gotcha:Commitsrequireanauthor!

Environmentvariables:GIT_AUTHOR_NAME,GIT_AUTHOR_EMAIL
Configfile:$ git repo-config user.name 'Eric S. Raymond'
Gecosvalue:/etc/passwd

Slide9
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

Branches:VisualizingBranches
$ git show-branch
! [jdl] Remove dead code.
* [master] Add copyright. Fix 80-column line.
! [origin] dtc: add setting of physical boot cpu
--* [master] Add copyright. Fix 80-column line.
+
[jdl] Remove dead code.
+*+ [origin] dtc: add setting of physical boot cpu

Branch Timeline
1
2

jdl
master
origin

time
Slide10
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

2
1

GitConcepts:Merges

Merge:Combinedirectoryandfilecontentsfromseparatesourcestoyield
onecombinedresult.

Sourcesformergesarelocalbranches
Mergesalwaysoccurinthecurrent,checkedoutbranch
Acompletemergeendswithanewcommit

Mergeresolutionisinherentlyambiguous
Gitusesseveralmergeheuristics:

Severalmergestrategies:resolve,recursive,octopus,ours
Techniques:fastforward,threeway

Somemergeconflictsmayneedtoberesolvedbythedeveloper
Slide11
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

MergejdlbranchTomaster
Branch Timeline

Mergejdlbranchintomaster
$ git checkout master
$ git pull . jdl

1
0

ResultingBranchHistory
$ git show-branch

jdl
3

origin
time

! [jdl] Remove dead code.


* [master] Merge branch 'jdl'
! [origin] dtc: add setting of physical boot cpu
--- [master] Merge branch 'jdl'
+* [jdl] Remove dead code.
* [master^] Add copyright. Fix 80-column line.
+*+ [origin] dtc: add setting of physical boot cpu
Slide12
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

master

Outline:UseCases

RepositoryManagement
LocalUseCases

PullingUpdates
MakingPatches
FindingaCommit
CherryPicking
RevertingaCommit
ResolvingMerges
RebasingLocalChanges

SupplementalSlides
Slide13
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

PullingUpdates
Original Repository

Thedefaultoriginremotesfile

master

$ cat .git/remotes/origin
URL: git://www.jdl.com/software/dtc.git
Pull: refs/heads/master:refs/heads/origin

Getupdatesfromremoterepository

git pull
Cloned Repository

$ git checkout master


$ git pull origin

Pullisafetchthenmerge

origin

Placesfetchedupdatesin
ref/heads/origin
Mergesoriginintothecurrent,
checkedoutbranch,master

Slide14
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

merge

master

Pull:FetchandMergeBranchTimeline
Before

After
Public Repository

Public Repository

master

master

1- fetch

2- fast-forward
origin
master

Your Repository

origin

3 - merge
master
Your Repository
time

time

Slide15
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

Pull:WhatElse?

Pullisafetchfollowedbyamerge

Mergesshouldstartwithsomecommonbase,though

Canfetch/pullanybranchfromanyrepository

SupplyURLoncommandlinedirectly
MaybeaddnewremotesfilewithURLandPull:line
Eventhisrepository:git pull . <branch>

Couldjustgit

fetchanupstreambranchtoo
Abletothencherry-pickcommitsratherthanfullmerge
Abletousegit diff,git log,etc.

Slide16
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

Pull:When?

Whenyouwantto!
Whenitisconvenient,stable,Wednesday...
Whentheupstreamtreeisstable
Whenyourworkingdirectoryisstable

...andyouhavetherightbranchcheckedout
Yourworkingdirectoryshouldprobablybeclean

git difforgit statusshouldbeempty

Technicallynotnecessary,but...

Slide17
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

SendingChangesUpstream

Generateandsendpatchesviaemail

Mostdeveloperssendpatchestoamaintainerorlist
Highlyvisiblepublicreviewofpatchesonmaillist

Maintainerpullsupdatesfromadownstreamdeveloper

Maintainercandirectlypullfromyourpublishedrepository
Initiatedbyupstreammaintainer

Developerpushesupdatestoanupstreammaintainer

Somedevelopershavewritepermissionsonanupstreamrepository
Initiatedbydownstreamdeveloper

Slide18
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

Patches:GenerateaPatch

Usegit

format-patchcommand

$ git format-patch --signoff origin..jdl


From: Jon Loeliger <[email protected]>
Date: Sat, 24 Jun 2006 15:42:51 -0500
Subject: [PATCH] Remove dead code.
Signed-off-by: Jon Loeliger <[email protected]>
--data.c |
18 -----------------1 files changed, 0 insertions(+), 18 deletions(-)
diff --git a/data.c b/data.c
index 911b271..d3b55f9 100644
--- a/data.c
+++ b/data.c
@@ -20,24 +20,6 @@

Slide19
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

Patches:ASideNote

ReadtheREADME
Followthecodingstandards
Compileandtestyourcode
Fixthewhitespaceissues
Knowwhotheupstreammaintaineris
Understandanysignoffpolicy

Slide20
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

Patches:FormattingandSendingMail

SendplainASCII,notHTML
Sendpatchesinline
Don'tuseattachments

Sendonlyyourchanges
Onelinecommitsummaryfirst
Becarefulofcutnpastesolutions

Usefilebrowseandinsertifpossible

Maybemovepreformattedpatches

toyourMUAdraftfolder
Sendgitformatpatchoutputdirectly
$ git send-email --to
[email protected] my.patch

Slide21
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

FindingaCommit

SHA1hashnamesareconstant
Symboliccommitnameslikemaster~4changeovertime!
TheyarerelativetothecurrentHEAD

Waystodeterminethenameofacommityouwant

git show-branch =>paul~38^2~10^2


Pawaroundingitk =>9ad494f62444ee37209e85173377c67612e66ef1
Usegit log -- <some/file/path>
Usegitweb

Note:
$ git rev-parse paul~38^2~10^2
9ad494f62444ee37209e85173377c67612e66ef1
Slide22
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

CherryPickingExample

Youwantoneormoreparticularcommitsfromsomeotherbranch
appliedtoyourcurrentbranch

Bugfixfromsomeotherbranch
Transferpartialfunctionalityfromdevelopmentbranch

Getthatcommitintoyourrepository

Alreadypresentonadifferentbranch
Perhapsusinggit fetchfromanotherrepository

Cherrypickitintoappropriatebranch
$ git checkout master
$ git cherry-pick 9ad494

Slide23
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

CherryPicking:BeforeandAfter

BranchTimelinePicture

4'isadifferentcommitwiththesamecontentas4
Before

mpc86xx
master

After

mpc86xx
master

time

4'

Slide24
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

RevertExample

Situation:

Somecommitburiedinthepastneedstobeundone
...andithasalreadybeenmergedtomastertoo!
$ git show-branch --more=10 master mpc86xx
*
!
-*+
*+
*+
*+
*+
*+
*+

[master] Merge branch 'mpc86xx'


[mpc86xx] Remove obsolete #include <someos/config.h>.
[master] Merge branch 'mpc86xx'
[mpc86xx] Remove obsolete #include <someos/config.h>.
[mpc86xx^] Remove redundant STD_MMU selection.
[mpc86xx~2] Move I8259 selection under MPC8641HPCN board.
[mpc86xx~3] Remove redundant PPC_86XX check.
[mpc86xx~4] Reworked the IRQ mapping. Now reading IRQ and ... <======ARGH!
[mpc86xx~5] Make 86xx secondary CPU start be more generic.
[mpc86xx~6] Updated 86xx defcnofig after merge with Paul

Thisisajobforgit

revert

Slide25
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

Revert:BeforeandAfter

Commit4isreverted,creatingcommit0inyellow
Commit0ismergedtomasterascommit0'
Before
6

mpc86xx
master

After

0
mpc86xx
master

0'
time
Slide26
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

Revert:Commands

Revertappliesanewinversepatchforagivencommit
Revertworkswithoutrewritingthecommithistory
Canrevertmultiplecommitsatthesametime
Revertcommitonmpc86xxtopicbranch:
$ git checkout mpc86xx
$ git revert mpc86xx~4

Reflectitontomasterbranchaswell:
$ git checkout master
$ git pull . mpc86xx

Slide27
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

Revert:BranchHistoryAfter
$ git show-branch --more=10 master mpc86xx
*
!
-*+
*+
*+
*+
*+
*+
*+
*+

[master] Merge branch 'mpc86xx'


[mpc86xx] Revert "Reworked the IRQ mapping. Now reading IRQ and ..."
[master] Merge branch 'mpc86xx'
[mpc86xx] Revert "Reworked the IRQ mapping. Now reading IRQ and ..."
[mpc86xx^] Remove obsolete #include <someos/config.h>.
[mpc86xx~2] Remove redundant STD_MMU selection.
[mpc86xx~3] Move I8259 selection under MPC8641HPCN board.
[mpc86xx~4] Remove redundant PPC_86XX check.
[mpc86xx~5] Reworked the IRQ mapping. Now reading IRQ and ...
[mpc86xx~6] Make 86xx secondary CPU start be more generic.
[mpc86xx~7] Updated 86xx defcnofig after merge with Paul

Slide28
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

RevertversusResetversusCheckout

ResetversusRevert:Tryingtoundothelastcommit?

Ask:Doessomeoneelsehavethisversionoftherepositoryhistory?

Yes:Usegit revertanddonotchangehistory
No:Couldusegit resetorgit commit --amendperhaps

ResetversusCheckout

Resetdoesn'tchangeyourcurrentbranch
Checkoutestablishesyourcurrentbranch
Thesecanbesimilarunlessnamingadifferentbranch:
git reset --hard topic
git checkout -f topic

# still on original branch,


#
but it now looks like topic!
# topic branch checked out now

Slide29
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

MergeResolutionHell...er,Examples

Pullingupdatesfromupstreamcangowrongforanumberofreasons!
Conflictingfilecontents
Newormodifiedfilesinyourworkingtree
Differentfilemodes
Possibleforyourupstreamchangestocomebackdifferently

Alteredupstreambymaintainer?
Weretheypulledorpatchedupstream?
Samefilecontent,butdifferentcommits?

Mergeisaheuristic!

Slide30
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

MergeResolutionStrategies

Beforedoingthepullormerge

Checkoutthecorrectmergeintobranch,likelymaster
Ensureacleanworkingdirectoryfirst
git ls-files --others
git status

Afterfailedpull/mergerequest:
git ls-files -u
git diff

# Show unmerged files remaining


# Clean if it matches one of the variants!

Makeprogressresolvingconflicts:
git update-index

# Tell git when a conflict has been resolved

Bedone:

Fullyresolved:git commit
Abandonmerge:git reset --hard

ORIG_HEAD

Slide31
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

FailedMerge:UntrackedWorkingTreeFile

Gitsays:
git-read-tree: fatal: Untracked working tree file
'Documentation/ABI/README' would be overwritten by merge.

Huh?Idon'thavethatfile...

Maybeyoudohavethatfileandshouldcheck!
Butmaybeitisleftoverfromapreviousmergeeffort?
Areyouontherightbranch?
git branch
git show-branch

Slide32
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

FailedMerge:UntrackedFileResolution

Yourkey:
git ls-files --others
git status
git clean -d

# Look for untracked files


# Check for unexpected files
# Remove cruft

Resettheworkingdirectory:

Maybeabandonthismerge?
Lookforotherfiles
Cleanouttheoldfiles
Dothemergeagain!

$
$
$
$

git
git
git
git

reset --hard ORIG_HEAD


ls-files --others
clean -d
status
# Ah! Nice-n-tidy

Slide33
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

FailedMerge:CONFLICTContent

Gitmessage:
CONFLICT (content): Merge conflict in drivers/net/phy/Makefile

Semitraditional"<<<<====>>>>"stylefilecontentdifferences.
$ git diff drivers/net/phy/Makefile
@@@ -8,4 -8,5 +8,9 @@@
obj-$(CONFIG_CICADA_PHY)
+= cicada.o
obj-$(CONFIG_LXT_PHY)
+= lxt.o
obj-$(CONFIG_QSEMI_PHY)
+= qsemi.o
++<<<<<<< HEAD/drivers/net/phy/Makefile
+obj-$(CONFIG_VITESSE_PHY)
+= vitesse.o
++=======
+ obj-$(CONFIG_SMSC_PHY)
+= smsc.o
+ obj-$(CONFIG_VITESSE_PHY)
+= vitesse.o
++>>>>>>>
501b7c77de3e90519e95fd99e923bf9a29cd120d/drivers/net/phy/Makefile

Slide34
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

FailedMerge:ResolveContentConflict

Yourkey:
git diff
git ls-files -s arch/somearch/Kconfig

# Various stage versions

Editandfix
Useyourfavoriteeditor,emacs
Makeprogress
git update-index arch/somearch/Kconfig

Slide35
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

FailedMerge:CONFLICTadd/add

Gitsayseither:

Added file3 in both, but differently. ERROR: Merge conflict in file3


CONFLICT (add/add):
File arch/somearch/platforms/86xx/mpc86xx_hpcn.c
added non-identically in both branches.
Adding as arch/somearch/platforms/86xx/mpc86xx_hpcn.c~HEAD
and arch/somearch/platforms/86xx/mpc86xx_hpcn.c~501b7c instead.

Twobranchesaddedthesamefile,butdifferently.

TheversionfrommymasterHEADisleftwith~HEADsuffix.
Theversionfromincomingoriginisleftwith~501b7csuffix.

Resolution:

Picktherightoneormergethem
Usegit addtoadditbackwiththerightname(drop~suffix)
Removetheother
Slide36
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

FailedMerge:CONFLICTrename/add

Gitsays:
CONFLICT (rename/add): Rename
arch/{mips/configs/ddb5476_defconfig =>
somearch/configs/mpc8641_hpcn_defconfig} in 501b7c...
arch/somearch/configs/mpc8641_hpcn_defconfig added in HEAD

Maybeitlies!

Renamedetectionisn't100%precise.Itisaheuristic!

ddb5476_defconfigjusthappenstoberemoved
mpc8641_hpcn_defconfigreallyadded!

Resolution:

Additback!Holycow!
Makesureindexhascorrect,addedfileandeither:
git update-index arch/somearch/configs/mpc8641_hpcn_defconfig
git add arch/somearch/configs/mpc8641_hpcn_defconfig
Slide37
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

RebaseLocalChangesExample

Situation:

Youhavedonedevelopmentworkonyourtopicbranch
Youpullinupstreamoriginandmergeittomaster
Youdon'twanttomergemasterintoyourtopicbranch
Youdon'twanttomergeyourtopicintothemasterbranch
Nooneelsehasclonedyourtopicbranch!

Why?Don'trewritehistory

Butyouwanttosendyourtopicbranchpatchesupstream!

Thisisajobforgit

rebase

Slide38
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

Rebase:BeforeandAfter

Rebasecommits04oftopicontomasterbranchatAas0'4'
Before

2
C

1
B

topic

After

master
origin

4'
C

3' 2'

time
Slide39
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

1'

0'

topic
master
origin

Rebase:Commands

RebaseCommands
$ git checkout topic
$ git rebase master

Createsaseriesofpatchesfromtopictobeappliedtomaster
Mayhavetoresolveconflictsateachstepduetomergeoperation
git rebase --continue
git rebase --skip
git rebase --abort

Slide40
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

GitResources

SourcesandDocumentation:

Gitsources,documentationandmanyrepositories:kernel.org/git
TheGitWiki:git.or.cz/gitwiki

FrontendsandViewers:

Cogito:kernel.org/pub/software/scm/cogito
StackedGit:www.procode.org/stgit
PatchyGit:www.spearce.org/category/projects/scm/pg
QTGuiviewer:sourceforge.net/project/qgit

MailList:[email protected]
IRC:freenode.net#git
Slide41
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

Outline:Supplemental

RepositoryManagement
LocalUseCases
SupplementalSlides

SendingChangesUpstreamUsingPullandPush
ScreenCaptureofgitk

Slide42
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

SendChangesUpstreamUsinggitpull

Upstreammaintainertrustsyouandyourwork
Youhavetheabilitytopublishapublicrepository
Youhavealotofchanges,morethanafewpatches
Advertiseyourrepositoryandbranch
Waitforupstreammaintainertopullit

$ git pull git://www.your-site.org/path/to/repo.git

Profit.

Slide43
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

UsingPull:DataFlowPicture
Public Repository

Maintainer's Repository
Instigator

from_jdl

master

git push

merge

Your Development
Repository

git pull

master

Slide44
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

master

SendingChangesUpstreamUsinggitpush

Directpushintoremoterepository

Sendsobjects,packs,branchestoremoterepository

Pushtoarepositoryfromwhichyouhavefetched
Canonlypushtoabranchthatisapropersubset
Shouldresultina"fastforward"ontheremoteend
Technicallyyoucanpushelsewhere,but...

Requireswriteaccessontheremoteend
Likelyviassh

Slide45
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

UsingPush:SetupRemotesFile

Createaremotesfile

StateupstreamrepositoryURL
Statebranchestobepushedupstream

Canpushmultiplebranches,asneeded

JustaddaPush:refspeclineforeachbranch

Canpushtodifferentremotebranchnames
Push: master:incoming
$ cat .git/remotes/publish
URL: ssh://www.jdl.com/software/dtc.git
Push: master:master
Push: jdl:jdl

Slide46
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

UsingPush:gitpush
$ git push publish
Password:
updating 'refs/heads/master'
from 38e8f8fd88dae07ef8ada9d6baa41b06a4d9ac9f
to
a73b7d43d4f60e76d82018fb9a4d137b089a1325
Generating pack...
Done counting 11 objects.
Result has 8 objects.
Deltifying 8 objects.
100% (8/8) done
Total 8, written 8 (delta 5), reused 0 (delta 0)
Unpacking 8 objects
refs/heads/master: 38e8f8 -> a73b7d

Slide47
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

UsingPush:DataFlowPicture
Public
Repository

master
jdl

git push

Your Development
Repository

push
instigator

jdl

master

Slide48
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

gitkExample

Slide49
TM

FreescaleandtheFreescalelogoare trademarks ofFreescaleSemiconductor,Inc.Allotherproductorservicenamesare


thepropertyoftheirrespectiveowners.FreescaleSemiconductor,Inc.2005.

You might also like