Вы находитесь на странице: 1из 11

11/6/2016 GitAboutVersionControl

distributedisthenewcentralized
Searchentiresite...

About
Documentation
Reference
Book
Videos
ExternalLinks
Blog
Downloads
GUIClients
Logos
Community

DownloadthisbookinPDF,mobi,orePubformforfree.

ThisbookistranslatedintoDeutsch,,,Franais,,Nederlands,,,Portugus(Brasil)andetina.

PartialtranslationsavailableinArabic,Espaol,Indonesian,Italiano,Suomi,,PolskiandTrke.

TranslationsstartedforAzrbaycandili,,Catal,Esperanto,Espaol(Nicaragua),, ,Magyar,NorwegianBokml,Romn,,
,TingVit,and.

ThesourceofthisbookishostedonGitHub.
Patches,suggestionsandcommentsarewelcome.

Chapters

1.1.GettingStarted

1.1.1AboutVersionControl
2.1.2AShortHistoryofGit
3.1.3GitBasics

https://gitscm.com/book/en/v2/GettingStartedAboutVersionControl 1/11
11/6/2016 GitAboutVersionControl

4.1.4TheCommandLine
5.1.5InstallingGit
6.1.6FirstTimeGitSetup
7.1.7GettingHelp
8.1.8Summary

2.2.GitBasics

1.2.1GettingaGitRepository
2.2.2RecordingChangestotheRepository
3.2.3ViewingtheCommitHistory
4.2.4UndoingThings
5.2.5WorkingwithRemotes
6.2.6Tagging
7.2.7GitAliases
8.2.8Summary

3.3.GitBranching

1.3.1BranchesinaNutshell
2.3.2BasicBranchingandMerging
3.3.3BranchManagement
4.3.4BranchingWorkflows
5.3.5RemoteBranches
6.3.6Rebasing
7.3.7Summary

4.4.GitontheServer

1.4.1TheProtocols
2.4.2GettingGitonaServer
3.4.3GeneratingYourSSHPublicKey
4.4.4SettingUptheServer
5.4.5GitDaemon
6.4.6SmartHTTP
7.4.7GitWeb
8.4.8GitLab
https://gitscm.com/book/en/v2/GettingStartedAboutVersionControl 2/11
11/6/2016 GitAboutVersionControl

9.4.9ThirdPartyHostedOptions
10.4.10Summary

5.5.DistributedGit

1.5.1DistributedWorkflows
2.5.2ContributingtoaProject
3.5.3MaintainingaProject
4.5.4Summary

1.6.GitHub

1.6.1AccountSetupandConfiguration
2.6.2ContributingtoaProject
3.6.3MaintainingaProject
4.6.4Managinganorganization
5.6.5ScriptingGitHub
6.6.6Summary

2.7.GitTools

1.7.1RevisionSelection
2.7.2InteractiveStaging
3.7.3StashingandCleaning
4.7.4SigningYourWork
5.7.5Searching
6.7.6RewritingHistory
7.7.7ResetDemystified
8.7.8AdvancedMerging
9.7.9Rerere
10.7.10DebuggingwithGit
11.7.11Submodules
12.7.12Bundling
13.7.13Replace
14.7.14CredentialStorage
15.7.15Summary

https://gitscm.com/book/en/v2/GettingStartedAboutVersionControl 3/11
11/6/2016 GitAboutVersionControl

3.8.CustomizingGit

1.8.1GitConfiguration
2.8.2GitAttributes
3.8.3GitHooks
4.8.4AnExampleGitEnforcedPolicy
5.8.5Summary

4.9.GitandOtherSystems

1.9.1GitasaClient
2.9.2MigratingtoGit
3.9.3Summary

5.10.GitInternals

1.10.1PlumbingandPorcelain
2.10.2GitObjects
3.10.3GitReferences
4.10.4Packfiles
5.10.5TheRefspec
6.10.6TransferProtocols
7.10.7MaintenanceandDataRecovery
8.10.8EnvironmentVariables
9.10.9Summary

1.A1.GitinOtherEnvironments

1.A1.1GraphicalInterfaces
2.A1.2GitinVisualStudio
3.A1.3GitinEclipse
4.A1.4GitinBash
5.A1.5GitinZsh
6.A1.6GitinPowershell
7.A1.7Summary

https://gitscm.com/book/en/v2/GettingStartedAboutVersionControl 4/11
11/6/2016 GitAboutVersionControl

2.A2.EmbeddingGitinyourApplications

1.A2.1CommandlineGit
2.A2.2Libgit2
3.A2.3JGit

3.A3.GitCommands

1.A3.1SetupandConfig
2.A3.2GettingandCreatingProjects
3.A3.3BasicSnapshotting
4.A3.4BranchingandMerging
5.A3.5SharingandUpdatingProjects
6.A3.6InspectionandComparison
7.A3.7Debugging
8.A3.8Patching
9.A3.9Email
10.A3.10ExternalSystems
11.A3.11Administration
12.A3.12PlumbingCommands

2ndEdition

1.1GettingStartedAboutVersionControl
ThischapterwillbeaboutgettingstartedwithGit.Wewillbeginbyexplainingsomebackgroundonversioncontroltools,thenmoveontohowtogetGit
runningonyoursystemandfinallyhowtogetitsetuptostartworkingwith.AttheendofthischapteryoushouldunderstandwhyGitisaround,whyyou
shoulduseitandyoushouldbeallsetuptodoso.

AboutVersionControl
Whatis"versioncontrol",andwhyshouldyoucare?Versioncontrolisasystemthatrecordschangestoafileorsetoffilesovertimesothatyoucanrecall
specificversionslater.Fortheexamplesinthisbookyouwillusesoftwaresourcecodeasthefilesbeingversioncontrolled,thoughinrealityyoucandothis
withnearlyanytypeoffileonacomputer.

https://gitscm.com/book/en/v2/GettingStartedAboutVersionControl 5/11
11/6/2016 GitAboutVersionControl

Ifyouareagraphicorwebdesignerandwanttokeepeveryversionofanimageorlayout(whichyouwouldmostcertainlywantto),aVersionControlSystem
(VCS)isaverywisethingtouse.Itallowsyoutorevertfilesbacktoapreviousstate,reverttheentireprojectbacktoapreviousstate,comparechangesover
time,seewholastmodifiedsomethingthatmightbecausingaproblem,whointroducedanissueandwhen,andmore.UsingaVCSalsogenerallymeansthatif
youscrewthingsuporlosefiles,youcaneasilyrecover.Inaddition,yougetallthisforverylittleoverhead.

LocalVersionControlSystems
Manypeoplesversioncontrolmethodofchoiceistocopyfilesintoanotherdirectory(perhapsatimestampeddirectory,iftheyreclever).Thisapproachis
verycommonbecauseitissosimple,butitisalsoincrediblyerrorprone.Itiseasytoforgetwhichdirectoryyoureinandaccidentallywritetothewrongfileor
copyoverfilesyoudontmeanto.

Todealwiththisissue,programmerslongagodevelopedlocalVCSsthathadasimpledatabasethatkeptallthechangestofilesunderrevisioncontrol.

https://gitscm.com/book/en/v2/GettingStartedAboutVersionControl 6/11
11/6/2016 GitAboutVersionControl

Figure11.Localversioncontrol.
https://gitscm.com/book/en/v2/GettingStartedAboutVersionControl 7/11
11/6/2016 GitAboutVersionControl

OneofthemorepopularVCStoolswasasystemcalledRCS,whichisstilldistributedwithmanycomputerstoday.EventhepopularMacOSXoperating
systemincludesthercscommandwhenyouinstalltheDeveloperTools.RCSworksbykeepingpatchsets(thatis,thedifferencesbetweenfiles)inaspecial
formatondiskitcanthenrecreatewhatanyfilelookedlikeatanypointintimebyaddingupallthepatches.

CentralizedVersionControlSystems
Thenextmajorissuethatpeopleencounteristhattheyneedtocollaboratewithdevelopersonothersystems.Todealwiththisproblem,CentralizedVersion
ControlSystems(CVCSs)weredeveloped.Thesesystems,suchasCVS,Subversion,andPerforce,haveasingleserverthatcontainsalltheversionedfiles,and
anumberofclientsthatcheckoutfilesfromthatcentralplace.Formanyyears,thishasbeenthestandardforversioncontrol.

https://gitscm.com/book/en/v2/GettingStartedAboutVersionControl 8/11
11/6/2016 GitAboutVersionControl

Figure12.Centralizedversioncontrol.

Thissetupoffersmanyadvantages,especiallyoverlocalVCSs.Forexample,everyoneknowstoacertaindegreewhateveryoneelseontheprojectisdoing.
AdministratorshavefinegrainedcontroloverwhocandowhatanditsfareasiertoadministeraCVCSthanitistodealwithlocaldatabasesoneveryclient.

However,thissetupalsohassomeseriousdownsides.Themostobviousisthesinglepointoffailurethatthecentralizedserverrepresents.Ifthatservergoes
downforanhour,thenduringthathournobodycancollaborateatallorsaveversionedchangestoanythingtheyreworkingon.Iftheharddiskthecentral
databaseisonbecomescorrupted,andproperbackupshaventbeenkept,youloseabsolutelyeverythingtheentirehistoryoftheprojectexceptwhatever

https://gitscm.com/book/en/v2/GettingStartedAboutVersionControl 9/11
11/6/2016 GitAboutVersionControl

singlesnapshotspeoplehappentohaveontheirlocalmachines.LocalVCSsystemssufferfromthissameproblemwheneveryouhavetheentirehistoryof
theprojectinasingleplace,yourisklosingeverything.

DistributedVersionControlSystems
ThisiswhereDistributedVersionControlSystems(DVCSs)stepin.InaDVCS(suchasGit,Mercurial,BazaarorDarcs),clientsdontjustcheckoutthelatest
snapshotofthefiles:theyfullymirrortherepository.Thusifanyserverdies,andthesesystemswerecollaboratingviait,anyoftheclientrepositoriescanbe
copiedbackuptotheservertorestoreit.Everycloneisreallyafullbackupofallthedata.

https://gitscm.com/book/en/v2/GettingStartedAboutVersionControl 10/11
11/6/2016 GitAboutVersionControl

Figure13.Distributedversioncontrol.

Furthermore,manyofthesesystemsdealprettywellwithhavingseveralremoterepositoriestheycanworkwith,soyoucancollaboratewithdifferentgroupsof
peopleindifferentwayssimultaneouslywithinthesameproject.Thisallowsyoutosetupseveraltypesofworkflowsthatarentpossibleincentralizedsystems,
suchashierarchicalmodels.

prev|next
ThisopensourcedsiteishostedonGitHub.
Patches,suggestionsandcommentsarewelcome.
GitisamemberofSoftwareFreedomConservancy

https://gitscm.com/book/en/v2/GettingStartedAboutVersionControl 11/11

Вам также может понравиться