ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
1.1.1-1.2-Git1.3-Git1.4-Git1.5-Git1.6-1.7-
2.Git2.1-Git2.2-2.3-2.4-2.5-2.6-2.7-2.8-
3.Git3.1-3.2-3.3-3.4-3.5-3.6-3.7-
4.Git4.1-4.2-Git4.3-SSH4.4-4.5-4.6-GitWeb4.7-Gitosis4.8-Git4.9-Git4.10-
5.Git5.1-5.2-5.3-5.4-
6.Git6.1-Revision6.2-6.3-Stashing6.4-6.5-Git6.6-6.7-6.8-
7.Git7.1-Git7.2-Git7.3-Git7.4-AnExampleGit-EnforcedPolicy7.5-Summary
8.Git8.1-GitSubversion8.2-Git8.3-
9.Git9.1-(Plumbing)(Porcelain)9.2-Git9.3-GitReferences9.4-Packfiles9.5-TheRefspec9.6-9.7-9.8-
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Chapter1
GitGitGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
VCS
1-1
1-1.
rcsMacOSXrcspatchrcs
CentralizedVersionControlSystemsCVCSCVSSubversionPerforce1-2
1-2.
VCSCVCS
DistributedVersionControlSystemDVCSGitMercurialBazaarDarcs1-3
1-3.
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGitGitGitSubversionPerforceGitGit
GitGitCVSSubversionPerforceBazaar1-4
1-4.
GitGitGitGit1-5
1-5.Git
GitGitVCSGit
GitCVCSGit
GitGit
CVCSVPNGitVPNPerforcePerforceSubversionCVS
GitchecksumGitGitGit
GitSHA-1SHA-1400-9a-f
24b9da6552252987aa493b52f8696cd6d3b00373
GitGit
GitVCSGit
Git“”
Gitcommittedmodifiedstaged
GitGit
1-6.git
gitGit
git
git
Git
1.2.3.git
git
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGit
GitLinuxdistrobackports
GitcurlzlibopensslexpatlibiconvyumFedoraapt-getDebian
$yuminstallcurl-develexpat-develgettext-devel\
openssl-develzlib-devel
$apt-getinstallcurl-develexpat-develgettext-devel\
openssl-develzlib-devel
Git
http://git-scm.com/download
$tar-zxfgit-1.6.0.5.tar.gz
$cdgit-1.6.0.5
$makeprefix=/usr/localall
$sudomakeprefix=/usr/localinstall
gitgitGit
$gitclonegit://git.kernel.org/pub/scm/git/git.git
Linux
LinuxGitFedorayum
$yuminstallgit-core
UbuntuDebianapt-get
$apt-getinstalgit-core
Mac
MacGitGit1-7
http://code.google.com/p/git-osx-installer
1-7.GitOSX
MacPorts(http://www.macports.org)MacPortsGit
$sudoportinstallgit-core+svn+doc+bash_completion+gitweb
MacportsGitSubversion+svn
Windows
WindowsGitmsysGitGoogleCode.exe
http://code.google.com/p/msysgit
gitsshGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGit
Gitgitconfiggit-configgitGit
/etc/gitconfig gitconfig --system~/.gitconfig gitconfig --globalgit .git/config .git/config /etc/gitconfig
WindowsGit .gitconfig $HOME C:\DocumentsandSettings\$USER
/etc/gitconfigGit
Git
$gitconfig--globaluser.name"JohnDoe"
--global --global .git/config
GitViVimEmacs
$gitconfig--globalcore.editoremacs
vimdiff
$gitconfig--globalmerge.toolvimdiff
Gitkdiff3tkdiffmeldxxdiffemergevimdiffgvimdiffecmergeopendiff
gitconfig--list
$gitconfig--list
user.name=ScottChacon
color.status=auto
color.branch=auto
color.interactive=auto
color.diff=auto
...
/etc/gitconfig ~/.gitconfigGit
$gitconfiguser.name
ScottChacon
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Git
$githelp<verb>
$git<verb>--help
$mangit-<verb>
config
$githelpconfig
FrenodeIRCirc.freenode.net #git #githubgit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitCVCSGitGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Chapter2
GitGitGitGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGitGitGit
Git
$gitinit
.gitGit .git
gitaddGit
$gitadd*.c
$gitaddREADME
$gitcommit-m'initialprojectversion'
Git
GitgitcloneVCSSubversionclonecheckoutGit
gitclone[url]RubyGitGrit
$gitclonegit://github.com/schacon/grit.git
“grit” .git grit
$gitclonegit://github.com/schacon/grit.gitmygrit
mygrit
Git git:// http(s):// user@server:/path.gitSSH
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
gitlog
simplegit
gitclonegit://github.com/schacon/simplegit-progit.git
gitlog
$gitlog
commitca82a6dff817ec66f44342007202690a93763949
Author:ScottChacon<[email protected]>
Date:MonMar1721:52:112008-0700
changedtheverisonnumber
commit085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author:ScottChacon<[email protected]>
Date:SatMar1516:40:332008-0700
removedunnecessarytestcode
commita11bef06a3f659402fe7563abf99ad00de2209e6
Author:ScottChacon<[email protected]>
Date:SatMar1510:31:282008-0700
firstcommit
gitlogSHA-1
gitlog
-p -2
$gitlog–p-2
commitca82a6dff817ec66f44342007202690a93763949
Author:ScottChacon<[email protected]>
Date:MonMar1721:52:112008-0700
changedtheverisonnumber
diff--gita/Rakefileb/Rakefile
indexa874b73..8f94139100644
---a/Rakefile
+++b/Rakefile
@@-5,7+5,7@@require'rake/gempackagetask'
spec=Gem::Specification.newdo|s|
-s.version="0.1.0"
+s.version="0.1.1"
s.author="ScottChacon"
commit085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author:ScottChacon<[email protected]>
Date:SatMar1516:40:332008-0700
removedunnecessarytestcode
diff--gita/lib/simplegit.rbb/lib/simplegit.rb
indexa0a60ae..47c6340100644
---a/lib/simplegit.rb
+++b/lib/simplegit.rb
@@-18,8+18,3@@classSimpleGit
end
end
-
-if$0==__FILE__
-git=SimpleGit.new
-putsgit.show
-end
\Nonewlineatendoffile
--stat
$gitlog--stat
commitca82a6dff817ec66f44342007202690a93763949
Author:ScottChacon<[email protected]>
Date:MonMar1721:52:112008-0700
changedtheverisonnumber
Rakefile|2+-
1fileschanged,1insertions(+),1deletions(-)
commit085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author:ScottChacon<[email protected]>
Date:SatMar1516:40:332008-0700
removedunnecessarytestcode
lib/simplegit.rb|5-----
1fileschanged,0insertions(+),5deletions(-)
commita11bef06a3f659402fe7563abf99ad00de2209e6
Author:ScottChacon<[email protected]>
Date:SatMar1510:31:282008-0700
firstcommit
README|6++++++
Rakefile|23+++++++++++++++++++++++
lib/simplegit.rb|25+++++++++++++++++++++++++
3fileschanged,54insertions(+),0deletions(-)
--pretty oneline shortfull fuller
$gitlog--pretty=oneline
ca82a6dff817ec66f44342007202690a93763949changedtheverisonnumber
085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7removedunnecessarytestcode
a11bef06a3f659402fe7563abf99ad00de2209e6firstcommit
format
$gitlog--pretty=format:"%h-%an,%ar:%s"
ca82a6d-ScottChacon,11monthsago:changedtheverisonnumber
085bb3b-ScottChacon,11monthsago:removedunnecessarytestcode
a11bef0-ScottChacon,11monthsago:firstcommit
2-1
%H commit
%h
%T tree
%t
%P parent
%p
%an author
%ae
%ad -date=
%ar
%cn (committer)
%ce
%cd
%cr
%s
_author__committer_
onelineformat --graphASCIIGrit
$gitlog--pretty=format:"%h%s"--graph
*2d3acf9ignoreerrorsfromSIGCHLDontrap
*5e3ee11Mergebranch'master'ofgit://github.com/dustin/grit
|\
|*420eac9Addedamethodforgettingthecurrentbranch.
*|30e367ctimeoutcodeandtests
*|5a09431addtimeoutprotectiontogrit
*|e1193f8supportforheadswithslashesinthem
|/
*d6016bcrequiretimeforxmlschema
*11d191eMergebranch'defunkt'intolocal
gitlog2-2
-p
--stat
--shortstat--stat
--name-only
--name-status
--abbrev-commitSHA-140
--relative-date“2weeksago”
--graphASCII
--prettyonelineshortfullfullerformat
gitlog -2 -<n> nGitpager
--since --until
$gitlog--since=2.weeks
“2008-01-15”“2years1day3minutesago”
--author --grep --all-match
gitlog --
2-3
-(n) n
--since,--after
--until,--before
--author
--committer
Git200810JunioHamanot/
$gitlog--pretty="%h:%s"--author=gitster--since="2008-10-01"\
--before="2008-11-01"--no-merges--t/
5610e3b-Fixtestcasefailurewhenextendedattribute
acd3b9e-Enhancehold_lock_file_for_{update,append}()
f563754-demonstratebreakageofdetachedcheckoutwi
d1a43f2-reset--hard/read-tree--reset-u:removeun
51a94af-Fix"checkout--track-bnewbranch"ondetac
b0ad11e-pull:allow"gitpullorigin$something:$cur
Git20,0006
GitgitkTcl/Tk gitlog gitloggitkgitk2-2
2-2.gitk
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
--amend
$gitcommit--amend
--amend
$gitcommit-m'initialcommit'
$gitaddforgotten_file
$gitcommit--amend
gitadd* gitstatus
$gitadd.
$gitstatus
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
#modified:README.txt
#modified:benchmarks.rb
#
“Changestobecommitted” gitresetHEAD<file>...benchmarks.rb
$gitresetHEADbenchmarks.rb
benchmarks.rb:locallymodified
$gitstatus
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
#modified:README.txt
#
#Changedbutnotupdated:
#(use"gitadd<file>..."toupdatewhatwillbecommitted)
#(use"gitcheckout--<file>..."todiscardchangesinworkingdirectory)
#
#modified:benchmarks.rb
#
benchmarks.rb
benchmarks.rb gitstatus
#Changedbutnotupdated:
#(use"gitadd<file>..."toupdatewhatwillbecommitted)
#(use"gitcheckout--<file>..."todiscardchangesinworkingdirectory)
#
#modified:benchmarks.rb
#
Git1.6.1
$gitcheckout--benchmarks.rb
$gitstatus
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
#modified:README.txt
#
stashing
Git --amendGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGit
BashshellGitGit contrib/completion git-completion.bash
cpgit-completion.bash~/.git-completion.bash
source~/.git-completion.bash
Mac /opt/local/etc/bash_completion.dLinux /etc/bash_completion.d/
Bash
WindowsmsysGitGitBash
GitTab
$gitco<tab><tab>
commitconfig
gitcoTabcommitconfig m<tab> gitcommit
gitlogTab
$gitlog--s<tab>
--shortstat--since=--src-prefix=--stat--summary
Git
Git gitconfig
$gitconfig--globalalias.cocheckout
$gitconfig--globalalias.brbranch
$gitconfig--globalalias.cicommit
$gitconfig--globalalias.ststatus
gitcommit gitciGit
$gitconfig--globalalias.unstage'resetHEAD--'
$gitunstagefileA
$gitresetHEADfileA
last
$gitconfig--globalalias.last'log-1HEAD'
$gitlast
commit66938dae3329c7aebe598c2246a8e6af90d04646
Author:JoshGoebel<[email protected]>
Date:TueAug2619:48:512008+0800
testforcurrenthead
Signed-off-by:ScottChacon<[email protected]>
GitGit !Git gitvisual
$gitconfig--globalalias.visual"!gitk"
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Chapter3
Git
Git“”GitGitGitGitGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGitGit
Gitcommit
SHA-1GitGitblob
$gitaddREADMEtest.rbLICENSE2
$gitcommit-m'initialcommitofmyproject'
gitcommitGitGittreeGit
Gitblobblobtreetreecommit3-1
3-1.
parent3-2
3-2.Git
GitcommitGitmastermaster
3-3.
Gittesting gitbranch
$gitbranchtesting
commit3-4
3-4.
GitHEADSubversionCVSHEADGitmaster3-5
3-5.HEAD
gitcheckouttesting
$gitcheckouttesting
HEADtesting3-6
3-6.HEAD
$vimtest.rb
$gitcommit-a-m'madeachange'
3-7
3-7.HEAD
testingmaster gitcheckoutcommitmaster
$gitcheckoutmaster
3-8
3-8.HEADcheckout
HEADmastermastertesting
$vimtest.rb
$gitcommit-a-m'madeotherchanges'
3-9 branch checkout
3-9.
Git40SHA-141
GitparentGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
1.2.3.
1.2.3.4.
3-10
3-10.
#53Gitiss53 gitcheckout -b
$gitcheckout-biss53
Switchedtoanewbranch"iss53"
$gitbranchiss53
$gitcheckoutiss53
3-11
3-11.
iss53HEAD3-12
$vimindex.html
$gitcommit-a-m'addedanewfooter[issue53]'
3-12.iss53
Git iss53master
Gitstashingamendingmaster
$gitcheckoutmaster
Switchedtobranch"master"
#53Gitcommit
hotfix3-13
$gitcheckout-b'hotfix'
Switchedtoanewbranch"hotfix"
$vimindex.html
$gitcommit-a-m'fixedthebrokenemailaddress'
[hotfix]:created3a0874c:"fixedthebrokenemailaddress"
1fileschanged,0insertions(+),1deletions(-)
3-13.hotfixmaster
master gitmerge
$gitcheckoutmaster
$gitmergehotfix
Updatingf42c576..3a0874c
Fastforward
README|1-
1fileschanged,0insertions(+),1deletions(-)
“Fastforward”mastercommithotfixGitGitFastforward
mastercommit3-14
3-14.masterhotfix
hotfix master gitbranch -d
$gitbranch-dhotfix
Deletedbranchhotfix(3a0874c).
#533-15
$gitcheckoutiss53
Switchedtobranch"iss53"
$vimindex.html
$gitcommit-a-m'finishedthenewfooter[issue53]'
[iss53]:createdad82d7a:"finishedthenewfooter[issue53]"
1fileschanged,1insertions(+),0deletions(-)
3-15.iss53
hotfix iss53 gitmergemastermaster iss53 iss53
#53 master hotfixmaster gitmerge
$gitcheckoutmaster
$gitmergeiss53
Mergemadebyrecursive.
README|1+
1fileschanged,1insertions(+),0deletions(-)
hotfixmastercommit(C4)iss53GitGitC4C5C23-16Git
3-16.Git
GitcommitC63-17commitmergecommit
GitCVSSubversion1.5Git
3-17.Gitcommit
iss53
$gitbranch-diss53
Git#53 hotfix
$gitmergeiss53
Auto-mergingindex.html
CONFLICT(content):Mergeconflictinindex.html
Automaticmergefailed;fixconflictsandthencommittheresult.
Git gitstatus
[master*]$gitstatus
index.html:needsmerge
#Onbranchmaster
#Changedbutnotupdated:
#(use"gitadd<file>..."toupdatewhatwillbecommitted)
#(use"gitcheckout--<file>..."todiscardchangesinworkingdirectory)
#
# unmerged:index.html
#
unmergedGit
<<<<<<<HEAD:index.html
<divid="footer">contact:[email protected]</div>
=======
<divid="footer">
</div>
>>>>>>>iss53:index.html
=======HEADmastermerge iss53
<divid="footer">
</div>
<<<<<<<=======>>>>>>> gitaddresolved
$gitmergetool
mergetoolcandidates:kdiff3tkdiffxxdiffmeldgvimdiffopendiffemergevimdiff
Mergingthefiles:index.html
Normalmergeconflictfor'index.html':
{local}:modified
{remote}:modified
Hitreturntostartmergeresolutiontool(opendiff):
Git opendiffMac”mergetoolcandidates”
Git
gitstatus
$gitstatus
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
# modified:index.html
#
gitcommit
Mergebranch'iss53'
Conflicts:
index.html
#
#ItlookslikeyoumaybecommittingaMERGE.
#Ifthisisnotcorrect,pleaseremovethefile
#.git/MERGE_HEAD
#andtryagain.
#
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
gitbranch
$gitbranch
iss53
*master
testing
master * mastercommit gitbranch-v
$gitbranch-v
iss5393b412cfixjavascriptissue
*master7a98805Mergebranch'iss53'
testing782fd34addscotttotheauthorlistinthereadmes
--merge --no-mergedGit1.5.6 gitbranch-merge
$gitbranch--merged
iss53
*master
iss53 * gitbranch-d
gitbranch--no-merged
$gitbranch--no-merged
testing
gitbranch-d
$gitbranch-dtesting
error:Thebranch'testing'isnotanancestorofyourcurrentHEAD.
-D gitbranch-Dtesting
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
remotebranchGit
()/() origin master origin/master iss53
origin/iss53
git.ourcompany.comGitGit origin master master origin master3-22
3-22.Gitmasterorigin/masterorigin/master
master git.ourcompany.com master origin/master
3-23.
gitfetchorigin origin git.ourcompany.com24
3-24.gitfetchremote
git.team1.ourcompany.com gitremoteadd teamone
3-25.
gitfetchteamone originGit teamone/master teamone
3-26
3-26.teamonemaster
serverfix gitpush()()
$gitpushoriginserverfix
Countingobjects:20,done.
Compressingobjects:100%(14/14),done.
Writingobjects:100%(15/15),1.74KiB,done.
Total15(delta5),reused0(delta0)
[email protected]:schacon/simplegit.git
*[newbranch]serverfix->serverfix
Git serverfix refs/heads/serverfix:refs/heads/serverfix“serverfixserverfix” refs/heads/ gitpushoriginserverfix:serferfix
serverfix”
origin/serverfix
$gitfetchorigin
remote:Countingobjects:20,done.
remote:Compressingobjects:100%(14/14),done.
remote:Total15(delta5),reused0(delta0)
Unpackingobjects:100%(15/15),done.
[email protected]:schacon/simplegit
*[newbranch]serverfix->origin/serverfix
fetch serverfix origin/serverfix
gitmergeorigin/serverfix serverfix
$gitcheckout-bserverfixorigin/serverfix
Branchserverfixsetuptotrackremotebranchrefs/remotes/origin/serverfix.
Switchedtoanewbranch"serverfix"
serverfix origin/serverfix
_(trackingbranch)_ gitpushGit gitpull
Git master origin/master gitpush gitpull origin
checkout-b[][]/[] 1.6.2Git --track
$gitcheckout--trackorigin/serverfix
Branchserverfixsetuptotrackremotebranchrefs/remotes/origin/serverfix.
Switchedtoanewbranch"serverfix"
$gitcheckout-bsforigin/serverfix
Branchsfsetuptotrackremotebranchrefs/remotes/origin/serverfix.
Switchedtoanewbranch"sf"
sf origin/serverfix
master gitpush[]:[] serverfix
$gitpushorigin:serverfix
[email protected]:schacon/simplegit.git
-[deleted]serverfix
gitpush[][]:[] [] “ [] ”
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
merge rebase
3-27
3-27.
mergeC3C4C23-28
3-28.
C3C4Git_rebase_ rebase
$gitcheckoutexperiment
$gitrebasemaster
First,rewindingheadtoreplayyourworkontopofit...
Applying:addedstagedcommand
diff3-29
3-29.C3C4
master3-30
3-30.master
C3C3’C5
origin/master
3-31 serverC3C4C3 clientC8C9
3-31.
C8C9 gitrebase --ontomaster
$gitrebase--ontomasterserverclient
“client client server master”3-32
3-32.
master3-33
$gitcheckoutmaster
$gitmergeclient
3-33.masterclient
server server master server gitrebase[][]
$gitrebasemasterserver
server master3-34
3-34.masterserver
master
$gitcheckoutmaster
$gitmergeserver
client server3-35
$gitbranch-dclient
$gitbranch-dserver
3-35.
commitcommitcommit gitrebasecommit
3-36
3-36.
C63-37
3-37.
C6 gitpush--forceC4’
3-38.C4’C6
commitSHA-1GitcommitC43-39:
3-39.C8
C4C4’SHA-1
commitcommitcommit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Chapter4
GitGitGit——“Git”Git
Git
(barerepository)——Git .git
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitSSHGitHTTP
HTTPGit
(Localprotocol)(NFS)
URL
$gitclone/opt/git/project.git
$gitclonefile:///opt/git/project.git
URL file://GitGit file://Git file://——9
Git
$gitremoteaddlocal_proj/opt/git/project.git
“Git”
gitpull/home/john/project
GitNFSSSH
SSH
GitSSHSSH——SSHHTTPGitSSHSSH
SSHGitssh://URL
$gitclonessh://user@server:project.git
——GitSSH
$gitcloneuser@server:project.git
Git
SSHSSHSSH——SSHSSH——GitSSH
SSHSSHSSHSSHSSH
Git
GitGitSSH9418Git git-export-daemon-ok
URL
GitGitSSH
GitGitSSH git://Git——“Gitosis”——9418
HTTP/S
HTTPHTTPHTTPSGitHTTP post-updatehookGitGitwebHTTP
$cd/var/www/htdocs/
$gitclone--bare/path/to/git_projectgitproject.git
$cdgitproject.git
$mvhooks/post-update.samplehooks/post-update
$chmoda+xhooks/post-update
Git post-updategitupdate-server-infoHTTPSSH
$gitclonehttp://example.com/gitproject.git
Apache /var/www/htdocsweb——Git9
HTTPWebDAVHTTPhttp://www.kernel.org/pub/software/scm/git/docs/howto/setup-git-server-over-http.txt
HTTPWebDAVGitWebDAV
HTTPHTTPHTTPApache——
HTTPSSSLSSHHTTPSSSLHTTP
HTTPHTTP
HTTPHTTP————HTTP (dumb)HTTP
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Git
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGit——clone --bare .git
$gitclone--baremy_projectmy_project.git
InitializedemptyGitrepositoryin/opt/projects/my_project.git/
clone gitinit gitfetch gitinit my_project.git
$cp-Rfmy_project/.gitmy_project.git
GitGit
git.example.comSSHGit /opt/git
[email protected]:/opt/git
SSH /opt/git
[email protected]:/opt/git/my_project.git
SSH /opt/git/my_project.git gitinit --sharedGit
$cd/opt/git/my_project.git
$gitinit--bare--shared
GitSSH
Git——SSH
GitosisSSH
GitGit
SSH
SSH
SSHSSH
adduser
gitSSH git ~/.ssh/authorized_keys git——commit
SSHLDAPshellSSH
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
SSHGitSSHSSH ~/.ssh
$cd~/.ssh
$ls
authorized_keys2id_dsaknown_hosts
configid_dsa.pub
.pub id_dsa id_rsa .pub .sshLinux/MacSSHWindowsMSysGit
$ssh-keygen
Generatingpublic/privatersakeypair.
Enterfileinwhichtosavethekey(/Users/schacon/.ssh/id_rsa):
Enterpassphrase(emptyfornopassphrase):
Entersamepassphraseagain:
Youridentificationhasbeensavedin/Users/schacon/.ssh/id_rsa.
Yourpublickeyhasbeensavedin/Users/schacon/.ssh/id_rsa.pub.
Thekeyfingerprintis:
43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:[email protected]
.ssh/id_rsa
GitSSH .pute-email
$cat~/.ssh/id_rsa.pub
ssh-rsaAAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tjom/BWDSU
GPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3
Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XA
t3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/En
mZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbx
SSHGitHubSSH http://github.com/guides/providing-your-ssh-key
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
SSH——
webGit post-update /opt/gitApachewebApache
$cdproject.git
$mvhooks/post-update.samplehooks/post-update
$chmoda+xhooks/post-update
Git1.6 mv——Git.sample
post-update
$cat.git/hooks/post-update
#!/bin/sh
execgit-update-server-info
SSHGitHTTP
ApacheVirtualHostDocumentRootGitDNS
<VirtualHost*:80>
ServerNamegit.gitserver
DocumentRoot/opt/git
<Directory/opt/git/>
Orderallow,deny
allowfromall
</Directory>
</VirtualHost>
/opt/gitUnix www-datawebApacheCGI
$chgrp-Rwww-data/opt/git
ApacheURL
$gitclonehttp://git.gitserver/project.git
HTTPGit——
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitWebGitGitWebCGI http://git.kernel.orgGitWeb4-1
Figure4-1.GitWeb
GitWebGit lighttpd webrickLinux lighttpd gitinstaweb
LeopardRuby webricklighttpd gitinstaweb
$gitinstaweb--httpd=webrick
[2009-02-2110:02:21]INFOWEBrick1.3.1
[2009-02-2110:02:21]INFOruby1.8.6(2008-03-03)[universal-darwin9.0]
1234HTTPD --stop
$gitinstaweb--httpd=webrick--stop
webCGILinux apt yum gitwebGitWebGitGitWebCGI
$gitclonegit://git.kernel.org/pub/scm/git/git.git
$cdgit/
$makeGITWEB_PROJECTROOT="/opt/git"\
prefix=/usrgitweb/gitweb.cgi
$sudocp-Rfgitweb/var/www/
GITWEB_PROJECTROOTGitApacheCGIVirtualHost
<VirtualHost*:80>
ServerNamegitserver
DocumentRoot/var/www/gitweb
<Directory/var/www/gitweb>
OptionsExecCGI+FollowSymLinks+SymLinksIfOwnerMatch
AllowOverrideAll
orderallow,deny
Allowfromall
AddHandlercgi-scriptcgi
DirectoryIndexgitweb.cgi
</Directory>
</VirtualHost>
GitWebCGIApache http://gitserverHTTPAgain,GitWebcanbeservedwithanyCGIcapablewebserver;ifyouprefertousesomethingelse,itshouldn’tbedifficulttosetup.Atthispoint,youshouldbeabletovisithttp://gitserver/toviewyourrepositoriesonline,andyoucanusehttp://git.gitserverfetchyourrepositoriesoverHTTP.
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Gitosis authorized_keysshell——
GitosisGitosis authorized_keysGitGitosis
GitosisLinux——Ubuntu8.10
GitosisPythonPythonsetuptoolsUbuntupython-setuptools
$apt-getinstallpython-setuptools
Gitosis
$gitclonegit://eagain.net/gitosis.git
$cdgitosis
$sudopythonsetup.pyinstall
GitosisGitosis /home/git /opt/git
$ln-s/opt/git/home/git/repositories
GitosisGitosis authorized_keys authorized_keys
$mv/home/git/.ssh/authorized_keys/home/git/.ssh/ak.bak
‘git’shell git-shellGitosis /etc/passwd
git:x:1000:1000::/home/git:/usr/bin/git-shell
:
git:x:1000:1000::/home/git:/bin/sh
Gitosis gitosis-init
$sudo-H-ugitgitosis-init</tmp/id_dsa.pub
InitializedemptyGitrepositoryin/opt/git/gitosis-admin.git/
ReinitializedexistingGitrepositoryin/opt/git/gitosis-admin.git/
GitosisGit post-update
$sudochmod755/opt/git/gitosis-admin.git/hooks/post-update
GitosisSSH
$sshgit@gitserver
PTYallocationrequestfailedonchannel0
fatal:unrecognizedcommand'gitosis-serveschacon@quaternion'
Connectiontogitserverclosed.
GitosisGitGit——Gitosis
#
$gitclonegit@gitserver:gitosis-admin.git
gitosis-admin
$cdgitosis-admin
$find.
./gitosis.conf
./keydir
./keydir/scott.pub
gitosis.conf keydir—— keydir scott.pub——Gitosis
gitosis.conf gitosis-admin
$catgitosis.conf
[gitosis]
[groupgitosis-admin]
writable=gitosis-admin
members=scott
scott——Gitosis—— gitosis-admin
mobile‘scott’ iphone_project
[groupmobile]
writable=iphone_project
members=scott
gitosis-admin
$gitcommit-am'addiphone_projectandmobilegroup'
[master]:created8962da8:"changedname"
1fileschanged,4insertions(+),0deletions(-)
$gitpush
Countingobjects:5,done.
Compressingobjects:100%(2/2),done.
Writingobjects:100%(3/3),272bytes,done.
Total3(delta1),reused0(delta0)
Togit@gitserver:/opt/git/gitosis-admin.git
fb27aec..8962da8master->master
iphone_projectremote——Gitosis
$gitremoteaddorigingit@gitserver:iphone_project.git
$gitpushoriginmaster
InitializedemptyGitrepositoryin/opt/git/iphone_project.git/
Countingobjects:3,done.
Writingobjects:100%(3/3),230bytes,done.
Total3(delta0),reused0(delta0)
Togit@gitserver:iphone_project.git
*[newbranch]master->master
——Gitosis
~/.ssh/authorized_keys keydir gitosis.confJohnJosieJessica
$cp/tmp/id_rsa.john.pubkeydir/john.pub
$cp/tmp/id_rsa.josie.pubkeydir/josie.pub
$cp/tmp/id_rsa.jessica.pubkeydir/jessica.pub
‘mobile’ iphone_project
[groupmobile]
writable=iphone_project
members=scottjohnjosiejessica
GitosisJohn
[groupmobile]
writable=iphone_project
members=scottjosiejessica
[groupmobile_ro]
readonly=iphone_project
members=john
JohnGitosis
loglevel=DEBUG [gitosis] /home/git/.gitosis
gitosis.conf gitosis-admin
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitHTTPGitGitHTTP
SSH
Git
gitdaemon--reuseaddr--base-path=/opt/git//opt/git/
--reuseaddr --base-pathGit9418
UbuntuUpstart
/etc/event.d/local-git-daemon
startonstartup
stoponshutdown
exec/usr/bin/gitdaemon\
--user=git--group=git\
--reuseaddr\
--base-path=/opt/git/\
/opt/git/
respawn
—— git-roGitosis‘git’
Git
initctlstartlocal-git-daemon
xinetdsysinit——
GitosisGitGitGitiphone gitosis.conf
[repoiphone_project]
daemon=yes
9418
GitosisGitGit
$cd/path/to/project.git
$touchgit-daemon-export-ok
git-deamon-export-okGit
GitosisGitWeb /etc/gitweb.conf
$projects_list="/home/git/gitosis/projects.list";
$projectroot="/home/git/repositories";
$export_ok="git-daemon-export-ok";
@git_base_url_list=('git://gitserver');
Gitosis gitwebGitWebiphoneGitWeb repo
[repoiphone_project]
daemon=yes
gitweb=yes
GitWebiphone
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.
AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGit——
GitwikiGithosting
http://git.or.cz/gitwiki/GitHosting
ScottChaconGitHub
GitHubGitGitHubGitHub
GitHub
GitHubGitHubGitHub grit github.com/grit github.com/shacon/grit
GitHubshacon
GitHub
PricingandSignup http://github.com/plansFreeacount“SignUp”4-2Thefirstthingyouneedtodoissetupafreeuseraccount.IfyouvisitthePricingandSignuppageathttp://github.com/plansandclickthe“SignUp”buttonontheFreeaccount(seefigure4-2),you’retakentothesignuppage.
Figure4-2.GitHub
4-3
Figure4-3.TheGitHubusersignupform
SSH””SSHPublicKeySSH“explainsshkeys”“Iagreesignmeup”4-4
Figure4-4.GitHub
“createanewone”CreateaNewRepository4-5
Figure4-5.GitHub
“CreateRepository”4-6
Figure4-6.GitHub
GitHubSubversiongooglecodesourceforge4-7
Figure4-7.
GitGit
$gitinit
$gitadd.
$gitcommit-m'initialcommit'
GitGitHubmaster
[email protected]:testinguser/iphone_project.git
$gitpushoriginmaster
GitHubURLURL http://github.com/testinguser/iphone_project
8
Figure4-8.URLURL
PublicCloneURLURLGitURLURL
YourCloneURLURLSSHURLSSHURL——
Subversion
SubversionGitGitHubSubversionSubversion4-9
Figure4-9.Subversion
JohnJosieJessicaGitHub
“edit”Admin4-10
Figure4-10.GitHub
“Addanothercollaborator”Add4-11
Figure4-11.
RepositoryCollaborators4-12
Figure4-12.
“revoke”
Subversion4-13
Figure4-13.GitHub
Commitscommit gitlogNetworkforkDownloadstar/zipWikiwikiGraphsSourceREADME
forking
GitHubforkingHack“fork”GitHub
mojombo/chronic“fork”4-14
Figure4-14.“fork”
4-15
Figure4-15.
GitHub
GitHubGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Chapter5
GitGitGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGit
peer-review
GitGit Documentation/SubmittingPatches
whitespaceGit gitdiff--check X
$gitdiff--check
lib/simplegit.rb:5:trailingwhitespace.
+@git_dir=File.expand_path(git_dir)XX
lib/simplegit.rb:7:trailingwhitespace.
+XXXXXXXXXXX
lib/simplegit.rb:26:trailingwhitespace.
+defcommand(git_cmd)XXXX
gitadd--patch
50Git“Iaddedtestsfor”“Addingtestsfor”“Addtestsfor”tpope.netTimPope
50
72
rebase
-
-
GitGit gitlog--no-mergesgit gitclone
git://git.kernel.org/pub/scm/git/git.git
-m gitcommit
SubversionGitJohn
#John'sMachine
$gitclonejohn@githost:simplegit.git
InitializedemptyGitrepositoryin/home/john/simplegit/.git/
...
$cdsimplegit/
$vimlib/simplegit.rb
$gitcommit-am'removedinvaliddefaultvalue'
[master738ee87]removedinvaliddefaultvalue
1fileschanged,1insertions(+),1deletions(-)
Jessica
#Jessica'sMachine
$gitclonejessica@githost:simplegit.git
InitializedemptyGitrepositoryin/home/jessica/simplegit/.git/
...
$cdsimplegit/
$vimTODO
$gitcommit-am'addresettask'
[masterfbff5bc]addresettask
1fileschanged,1insertions(+),0deletions(-)
Jessica
#Jessica'sMachine
$gitpushoriginmaster
...
Tojessica@githost:simplegit.git
1edee6b..fbff5bcmaster->master
John
#John'sMachine
$gitpushoriginmaster
Tojohn@githost:simplegit.git
![rejected]master->master(non-fastforward)
error:failedtopushsomerefsto'john@githost:simplegit.git'
JohnJessicaSubversionSubversionGitJohnJessica
$gitfetchorigin
...
Fromjohn@githost:simplegit
+049d078...fbff5bcmaster->origin/master
John5-4
5-4.John
JohnJessicafbff5 origin/master master738ee
$gitmergeorigin/master
Mergemadebyrecursive.
TODO|1+
1fileschanged,1insertions(+),0deletions(-)
John5-5
5-5.origin/masterJohn
John72bbc
$gitpushoriginmaster
...
Tojohn@githost:simplegit.git
fbff5bc..72bbc59master->master
John5-6
5-6.John
Jessica issue54John5-7
5-7.Jessica
Jessica
#Jessica'sMachine
$gitfetchorigin
...
Fromjessica@githost:simplegit
fbff5bc..72bbc59master->origin/master
JessicaJohn738ee72bbc5-8
5-8.JohnJessica
Jessica gitlog
$gitlog--no-mergesorigin/master^issue54
commit738ee872852dfaa9d6634e0dea7a324040193016
Author:JohnSmith<[email protected]>
Date:FriMay2916:01:272009-0700
removedinvaliddefaultvalue
Jessica masterJohn origin/master master
$gitcheckoutmaster
Switchedtobranch"master"
Yourbranchisbehind'origin/master'by2commits,andcanbefast-forwarded.
origin/master issue54upstreamupstreamJessicaissue54
$gitmergeissue54
Updatingfbff5bc..4af4298
Fastforward
README|1+
lib/simplegit.rb|6+++++-
2fileschanged,6insertions(+),1deletions(-)
JessicaJohn origin/master
$gitmergeorigin/master
Auto-merginglib/simplegit.rb
Mergemadebyrecursive.
lib/simplegit.rb|2+-
1fileschanged,1insertions(+),1deletions(-)
Jessica5-9
5-9.JohnJessica
Jessica master origin/masterJohn
$gitpushoriginmaster
...
Tojessica@githost:simplegit.git
72bbc59..8059c15master->master
5-10
5-10.Jessica
master origin/master5-11
5-11.
JohnJessicaAJessicaJosieB master
JessicaA featureA
#Jessica'sMachine
$gitcheckout-bfeatureA
Switchedtoanewbranch"featureA"
$vimlib/simplegit.rb
$gitcommit-am'addlimittologfunction'
[featureA3300904]addlimittologfunction
1fileschanged,1insertions(+),1deletions(-)
John featureAJessica masterJohn
$gitpushoriginfeatureA
...
Tojessica@githost:simplegit.git
*[newbranch]featureA->featureA
JessicaJohn featureAJessicaJosie featureBB
#Jessica'sMachine
$gitfetchorigin
$gitcheckout-bfeatureBorigin/master
Switchedtoanewbranch"featureB"
Jessica featureB
$vimlib/simplegit.rb
$gitcommit-am'madethels-treefunctionrecursive'
[featureBe5b0fdc]madethels-treefunctionrecursive
1fileschanged,1insertions(+),1deletions(-)
$vimlib/simplegit.rb
$gitcommit-am'addls-files'
[featureB8512791]addls-files
1fileschanged,5insertions(+),0deletions(-)
Jessica5-12
5-12.Jessica
JessicaJosie featureBeeJessicaJosie
$gitfetchorigin
...
Fromjessica@githost:simplegit
*[newbranch]featureBee->origin/featureBee
Jessica gitmerge
$gitmergeorigin/featureBee
Auto-merginglib/simplegit.rb
Mergemadebyrecursive.
lib/simplegit.rb|4++++
1fileschanged,4insertions(+),0deletions(-)
featureB featureBee:
$gitpushoriginfeatureB:featureBee
...
Tojessica@githost:simplegit.git
fba9af8..cd685d1featureB->featureBee
_refspec_Gitrefspec
JohnJessica featureAJessica gitfetch
$gitfetchorigin
...
Fromjessica@githost:simplegit
3300904..aad881dfeatureA->origin/featureA
gitlog
$gitlogorigin/featureA^featureA
commitaad881d154acdaeb2b6b18ea0e827ed8a6d671e6
Author:JohnSmith<[email protected]>
Date:FriMay2919:57:332009-0700
changedlogoutputto30from25
John featureA
$gitcheckoutfeatureA
Switchedtobranch"featureA"
$gitmergeorigin/featureA
Updating3300904..aad881d
Fastforward
lib/simplegit.rb|10+++++++++-
1fileschanged,9insertions(+),1deletions(-)
Jessica
$gitcommit-am'smalltweak'
[featureAed774b3]smalltweak
1fileschanged,1insertions(+),1deletions(-)
$gitpushoriginfeatureA
...
Tojessica@githost:simplegit.git
3300904..ed774b3featureA->featureA
Jessica5-13
5-13.
JessicaJosieJohn featureA featureBee5399efetch5-14
5-14.Jessica
GitGit5-15
5-15.
gitforkrepo.or.czGitHub
$gitclone(url)
$cdproject
$gitcheckout-bfeatureA
$(work)
$gitcommit
$(work)
$gitcommit
rebase-i–
“Fork”url git://githost/simplegit.git
$gitremoteaddmyfork(url)
mastercherrypickrewindmastercherry-pickfeatureA
$gitpushmyforkfeatureA
pullrequestGitHub“pullrequest” gitrequest-pull
request-pullGitURL myforkJessicaJohnpullrequst
$gitrequest-pullorigin/mastermyfork
Thefollowingchangessincecommit1edee6b1d61823a2de3b09c160d7080b8d1b3a40:
JohnSmith(1):
addedanewfunction
areavailableinthegitrepositoryat:
git://githost/simplegit.gitfeatureA
JessicaSmith(2):
addlimittologfunction
changelogoutputto30from25
lib/simplegit.rb|10+++++++++-
1fileschanged,9insertions(+),1deletions(-)
master origin/master master
$gitcheckout-bfeatureBorigin/master
$(work)
$gitcommit
$gitpushmyforkfeatureB
$(emailmaintainer)
$gitfetchorigin
AB5-16
5-16.featureB
origin/master
$gitcheckoutfeatureA
$gitrebaseorigin/master
$gitpush-fmyforkfeatureA
5-17
5-17.featureA
-fforce featureAcommit featureAv2
origin/master featureBv2 featureB
$gitcheckout-bfeatureBv2origin/master
$gitmerge--no-commit--squashfeatureB
$(changeimplementation)
$gitcommit
$gitpushmyforkfeatureBv2
--squash --no-commitGit
featureBv25-18
5-18.featureBv2
$gitcheckout-btopicA
$(work)
$gitcommit
$(work)
$gitcommit
gitformat-patchmbox .patchmboxGit
$gitformat-patch-Morigin/master
0001-add-limit-to-log-function.patch
0002-changed-log-output-to-30-from-25.patch
format-patch -MGit
$cat0001-add-limit-to-log-function.patch
From330090432754092d704da8e76ca5c05c198e71a8MonSep1700:00:002001
From:JessicaSmith<[email protected]>
Date:Sun,6Apr200810:17:23-0700
Subject:[PATCH1/2]addlimittologfunction
Limitlogfunctionalitytothefirst20
---
lib/simplegit.rb|2+-
1fileschanged,1insertions(+),1deletions(-)
diff--gita/lib/simplegit.rbb/lib/simplegit.rb
index76f47bc..f9815f1100644
---a/lib/simplegit.rb
+++b/lib/simplegit.rb
@@-14,7+14,7@@classSimpleGit
end
deflog(treeish='master')
-command("gitlog#{treeish}")
+command("gitlog-n20#{treeish}")
end
defls_tree(treeish='master')
--
1.6.2.rc1.20.g8c5b.dirty
--- Limitlogfunctionalitytothefirst20
GitIMAPGmailIMAPGitDocumentation/SubmittingPatches
~/.gitconfigimap gitconfig
[imap]
folder="[Gmail]/Drafts"
host=imaps://imap.gmail.com
pass=p4ssw0rd
port=993
sslverify=false
IMAPSSLhost imap:// s imaps:// gitsend-email
Gmail [Gmail]/DraftsDrafts
$gitsend-email*.patch
0001-added-limit-to-log-function.patch
0002-changed-log-output-to-30-from-25.patch
Whoshouldtheemailsappeartobefrom?[JessicaSmith<[email protected]>]
Emailswillbesentfrom:JessicaSmith<[email protected]>
Message-IDtobeusedasIn-Reply-Toforthefirstemail?y
Git
(mbox)Addingcc:JessicaSmith<[email protected]>from
\line'From:JessicaSmith<[email protected]>'
OK.Logsays:
Sendmail:/usr/sbin/[email protected]
From:JessicaSmith<[email protected]>
Subject:[PATCH1/2]addedlimittologfunction
Date:Sat,30May200913:29:15-0700
Message-Id:<[email protected]>
X-Mailer:git-send-email1.6.2.rc1.20.g8c5b.dirty
In-Reply-To:<y>
References:<y>
Result:OK
GmailDraftsCc
GitGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGitGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Chapter6
GitGit
Git
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
RevisionGit
SHA-1
SHA
GitSHA-1——SHA-1
gitlog
$gitlog
commit734713bc047d87bf7eac9674765ae793478c50d3
Author:ScottChacon<[email protected]>
Date:FriJan218:32:332009-0800
fixedrefshandling,addedgcauto,updatedtests
commitd921970aadf03b3cf0e71becdaab3147ba71cdef
Merge:1c002dd...35cfb2b...
Author:ScottChacon<[email protected]>
Date:ThuDec1115:08:432008-0800
Mergecommit'phedders/rdocs'
commit1c002dd4b536e7479fe34593e72e6c6c1819e53b
Author:ScottChacon<[email protected]>
Date:ThuDec1114:58:322008-0800
addedsomeblameandmergestuff
1c002dd.... gitshow
$gitshow1c002dd4b536e7479fe34593e72e6c6c1819e53b
$gitshow1c002dd4b536e7479f
$gitshow1c002d
GitSHA-1 --abbrev-commit gitlogSHA-1
$gitlog--abbrev-commit--pretty=oneline
ca82a6dchangedtheverisonnumber
085bb3bremovedunnecessarytestcode
a11bef0firstcommit
SHA-1GitLinux4012
SHA-1
SHA-1
SHA-1GitGit
SHA-12016050%2^80 p=(n(n-1)/2)*(1/2^160))
1.2x10^241200
SHA-165LinuxGitGit550%SHA-1
SHA-1Git topic1 ca82a6d
$gitshowca82a6dff817ec66f44342007202690a93763949
$gitshowtopic1
SHASHA-1 rev-parseGit9 rev-parseGit
$gitrev-parsetopic1
ca82a6dff817ec66f44342007202690a93763949
Git——HEAD
gitreflog
$gitreflog
734713b...HEAD@{0}:commit:fixedrefshandling,addedgcauto,updated
d921970...HEAD@{1}:mergephedders/rdocs:Mergemadebyrecursive.
1c002dd...HEAD@{2}:commit:addedsomeblameandmergestuff
1c36188...HEAD@{3}:rebase-i(squash):updatingHEAD
95df984...HEAD@{4}:commit:#Thisisacombinationoftwocommits.
1c36188...HEAD@{5}:rebase-i(squash):updatingHEAD
7e05da5...HEAD@{6}:rebase-i(pick):updatingHEAD
GitHEAD @{n}
$gitshowHEAD@{5}
master
$gitshowmaster@{yesterday}
gitlog gitlog-g
$gitlog-gmaster
commit734713bc047d87bf7eac9674765ae793478c50d3
Reflog:master@{0}(ScottChacon<[email protected]>)
Reflogmessage:commit:fixedrefshandling,addedgcauto,updated
Author:ScottChacon<[email protected]>
Date:FriJan218:32:332009-0800
fixedrefshandling,addedgcauto,updatedtests
commitd921970aadf03b3cf0e71becdaab3147ba71cdef
Reflog:master@{1}(ScottChacon<[email protected]>)
Reflogmessage:mergephedders/rdocs:Mergemadebyrecursive.
Author:ScottChacon<[email protected]>
Date:ThuDec1115:08:432008-0800
Mergecommit'phedders/rdocs'
—— gitshowHEAD@{2.months.ago}——
^Git
$gitlog--pretty=format:'%h%s'--graph
*734713bfixedrefshandling,addedgcauto,updatedtests
*d921970Mergecommit'phedders/rdocs'
|\
|*35cfb2bSomerdocchanges
*|1c002ddaddedsomeblameandmergestuff
|/
*1c36188ignore*.gem
*9b29157addopen3_detachtogemspecfilelist
HEAD^“HEAD”
$gitshowHEAD^
commitd921970aadf03b3cf0e71becdaab3147ba71cdef
Merge:1c002dd...35cfb2b...
Author:ScottChacon<[email protected]>
Date:ThuDec1115:08:432008-0800
Mergecommit'phedders/rdocs'
^—— d921970^2“d921970”
$gitshowd921970^
commit1c002dd4b536e7479fe34593e72e6c6c1819e53b
Author:ScottChacon<[email protected]>
Date:ThuDec1114:58:322008-0800
addedsomeblameandmergestuff
$gitshowd921970^2
commit35cfb2b795a55793d7cc56a6cc2060b4bb732548
Author:PaulHedderly<[email protected]>
Date:WedDec1022:22:032008+0000
Somerdocchanges
~ HEAD~ HEAD^ HEAD~2“”“”—— HEAD~3
$gitshowHEAD~3
commit1c3618887afb5fbcbea25b7c013f4e2114448b8d
Author:TomPreston-Werner<[email protected]>
Date:FriNov713:47:592008-0500
ignore*.gem
HEAD^^^
$gitshowHEAD^^^
commit1c3618887afb5fbcbea25b7c013f4e2114448b8d
Author:TomPreston-Werner<[email protected]>
Date:FriNov713:47:592008-0500
ignore*.gem
—— HEAD~3^2
——“”
Git6-1
6-1.
master..experimentGit——“experimentmaster”
$gitlogmaster..experiemnt
D
C
—— master experiment—— experiment..master master
$gitlogexperiment..master
F
E
experiment
$gitlogorigin/master..HEAD
origin gitpush origin/mastergitlogorigin/master..HEADGitHEADgitlogorigin/master..——GitHEAD
Git ^--not
$gitlogrefA..refB
$gitlog^refArefB
$gitlogrefB--notrefA
refArefBrefC
$gitlogrefArefB^refC
$gitlogrefArefB--notrefC
6-1 masterexperiment
$gitlogmaster...experiment
F
E
D
C
log
log--left-right
$gitlog--left-rightmaster...experiment
<F
<E
>D
>C
Git
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGitstash——
$gitcommit--amend
gitaddgitrmgitcommit--amend
SHA-1rebase——
GitrebaseHEADrebase gitrebase-irebase
gitrebase-i HEAD~2HEAD~3~3
$gitrebase-iHEAD~3
——HEAD~3..HEAD——
pickf7f3f6dchangedmynameabit
pick310154eupdatedREADMEformattingandaddedblame
picka5f4a0daddedcat-file
#Rebase710f0f8..a5f4a0donto710f0f8
#
#Commands:
#p,pick=usecommit
#e,edit=usecommit,butstopforamending
#s,squash=usecommit,butmeldintopreviouscommit
#
#IfyouremovealinehereTHATCOMMITWILLBELOST.
#However,ifyouremoveeverything,therebasewillbeaborted.
#
log log
$gitlog--pretty=format:"%h%s"HEAD~3..HEAD
a5f4a0daddedcat-file
310154eupdatedREADMEformattingandaddedblame
f7f3f6dchangedmynameabit
rebase( HEAD~3)
pickedit
editf7f3f6dchangedmynameabit
pick310154eupdatedREADMEformattingandaddedblame
picka5f4a0daddedcat-file
Git
$gitrebase-iHEAD~3
Stoppedat7482e0d...updatedthegemspectohopefullyworkbetter
Youcanamendthecommitnow,with
gitcommit--amend
Onceyou’resatisfiedwithyourchanges,run
gitrebase--continue
$gitcommit--amend
$gitrebase--continue
pickeditGit
”addedcat-file”rebase
pickf7f3f6dchangedmynameabit
pick310154eupdatedREADMEformattingandaddedblame
picka5f4a0daddedcat-file
pick310154eupdatedREADMEformattingandaddedblame
pickf7f3f6dchangedmynameabit
Git 310154ef7f3f6d”addedcat-file”
(Squashing)
rebase
#
#Commands:
#p,pick=usecommit
#e,edit=usecommit,butstopforamending
#s,squash=usecommit,butmeldintopreviouscommit
#
#IfyouremovealinehereTHATCOMMITWILLBELOST.
#However,ifyouremoveeverything,therebasewillbeaborted.
#
”pick””edit””squash”Git
pickf7f3f6dchangedmynameabit
squash310154eupdatedREADMEformattingandaddedblame
squasha5f4a0daddedcat-file
Git
#Thisisacombinationof3commits.
#Thefirstcommit'smessageis:
changedmynameabit
#Thisisthe2ndcommitmessage:
updatedREADMEformattingandaddedblame
#Thisisthe3rdcommitmessage:
addedcat-file
”updatedREADMEformattingandaddedblame””updatedREADMEformatting””addedblame” rebase-i”edit”
pickf7f3f6dchangedmynameabit
edit310154eupdatedREADMEformattingandaddedblame
picka5f4a0daddedcat-file
Git f7f3f6d 310154e gitresetHEAD^
continue
$gitresetHEAD^
$gitaddREADME
$gitcommit-m'updatedREADMEformatting'
$gitaddlib/simplegit.rb
$gitcommit-m'addedblame'
$gitrebase--continue
Gita5f4a0d
$gitlog-4--pretty=format:"%h%s"
1c002ddaddedcat-file
9b29157addedblame
35cfb2bupdatedREADMEformatting
f3cc40echangedmynameabit
SHA
:filter-branch
—— filter-branch
gitadd. filter-branchpassword.txt filter-branch
$gitfilter-branch--tree-filter'rm-fpasswords.txt'HEAD
Rewrite6b9b3cf04e7c5686a9cb838c3f36a8cb6a0fc2bd(21/21)
Ref'refs/heads/master'wasrewritten
--tree-filterpassword.txt gitfilter-branch--tree-filter'rm-f*~'HEAD
Githard-reset filter-branch --all
trunk,tags trunk filter-branch
$gitfilter-branch--subdirectory-filtertrunkHEAD
Rewrite856f0bf61e41a27326cdae8f09fe708d679f596f(12/12)
Ref'refs/heads/master'wasrewritten
trunkGit
gitconfig filter-branch --commit-filter
$gitfilter-branch--commit-filter'
if["$GIT_AUTHOR_EMAIL"="schacon@localhost"];
then
GIT_AUTHOR_NAME="ScottChacon";
GIT_AUTHOR_EMAIL="[email protected]";
gitcommit-tree"$@";
else
gitcommit-tree"$@";
fi'HEAD
SHA-1
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGitGit
gitblame -L1222
$gitblame-L12,22simplegit.rb
^4832fe2(ScottChacon2008-03-1510:31:28-070012)defshow(tree='master')
^4832fe2(ScottChacon2008-03-1510:31:28-070013)command("gitshow#{tree}")
^4832fe2(ScottChacon2008-03-1510:31:28-070014)end
^4832fe2(ScottChacon2008-03-1510:31:28-070015)
9f6560e4(ScottChacon2008-03-1721:52:20-070016)deflog(tree='master')
79eaf55d(ScottChacon2008-04-0610:15:08-070017)command("gitlog#{tree}")
9f6560e4(ScottChacon2008-03-1721:52:20-070018)end
9f6560e4(ScottChacon2008-03-1721:52:20-070019)
42cf2861(MagnusChacon2008-04-1310:45:01-070020)defblame(path)
42cf2861(MagnusChacon2008-04-1310:45:01-070021)command("gitblame#{path}")
42cf2861(MagnusChacon2008-04-1310:45:01-070022)end
SHA-1———— ^4832fe2Git ^SHA
Git gitblame-CGit GITServerHandler.m GITPackUpload.m
blame
$gitblame-C-L141,153GITPackUpload.m
f344f58dGITServerHandler.m(Scott2009-01-04141)
f344f58dGITServerHandler.m(Scott2009-01-04142)-(void)gatherObjectShasFromC
f344f58dGITServerHandler.m(Scott2009-01-04143){
70befdddGITServerHandler.m(Scott2009-03-22144)//NSLog(@"GATHERCOMMI
ad11ac80GITPackUpload.m(Scott2009-03-24145)
ad11ac80GITPackUpload.m(Scott2009-03-24146)NSString*parentSha;
ad11ac80GITPackUpload.m(Scott2009-03-24147)GITCommit*commit=[g
ad11ac80GITPackUpload.m(Scott2009-03-24148)
ad11ac80GITPackUpload.m(Scott2009-03-24149)//NSLog(@"GATHERCOMMI
ad11ac80GITPackUpload.m(Scott2009-03-24150)
56ef2cafGITServerHandler.m(Scott2009-01-05151)if(commit){
56ef2cafGITServerHandler.m(Scott2009-01-05152)[refDictsetOb
56ef2cafGITServerHandler.m(Scott2009-01-05153)
Git
bisect bisect
bisect gitbisectstart gitbisectbadbisect[good_commit]
$gitbisectstart
$gitbisectbad
$gitbisectgoodv1.0
Bisecting:6revisionslefttotestafterthis
[ecb6e1bc347ccecc5f9350d878ce677feb13d3b2]errorhandlingonrepo
Git(v1.0)12 gitbisectgoodGit
$gitbisectgood
Bisecting:3revisionslefttotestafterthis
[b047b02ea83310a70fd603dc8cd7a6cd13d15c04]securethisthing
gitbisectbadGit
$gitbisectbad
Bisecting:1revisionslefttotestafterthis
[f71ce38690acf49c1f3c9bea38e09d82a5ce6014]dropexceptionstable
GitSHA-1
$gitbisectgood
b047b02ea83310a70fd603dc8cd7a6cd13d15c04isfirstbadcommit
commitb047b02ea83310a70fd603dc8cd7a6cd13d15c04
Author:PJHyett<[email protected]>
Date:TueJan2714:48:322009-0800
securethisthing
:04000004000040ee3e7821b895e52c1695092db9bdc4c61d1730
f24d3c6ebcfc639b1a3814550e62d60b8e68a8e4Mconfig
gitbisectresetHEAD
$gitbisectreset
00 gitbisect bisectstart
$gitbisectstartHEADv1.0
$gitbisectruntest-error.sh
test-error.shGit makemaketests
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGit__Git__————
__rack
Git——
RackRack
[email protected]:schacon/rack.git
$gitfetchrack_remote
warning:nocommoncommits
remote:Countingobjects:3184,done.
remote:Compressingobjects:100%(1465/1465),done.
remote:Total3184(delta1952),reused2770(delta1675)
Receivingobjects:100%(3184/3184),677.42KiB|4KiB/s,done.
Resolvingdeltas:100%(1952/1952),done.
[email protected]:schacon/rack
*[newbranch]build->rack_remote/build
*[newbranch]master->rack_remote/master
*[newbranch]rack-0.4->rack_remote/rack-0.4
*[newbranch]rack-0.9->rack_remote/rack-0.9
$gitcheckout-brack_branchrack_remote/master
Branchrack_branchsetuptotrackremotebranchrefs/remotes/rack_remote/master.
Switchedtoanewbranch"rack_branch"
rack_branchRack master
$ls
AUTHORSKNOWN-ISSUESRakefilecontrib lib
COPYINGREADMEbinexample test
$gitcheckoutmaster
Switchedtobranch"master"
$ls
README
Rack masterGit gitread-tree9 read-tree master
$gitread-tree--prefix=rack/-urack_branch
Rack——tarballRack
$gitcheckoutrack_branch
$gitpull
master gitmerge-ssubtreeGit -ssubtree--squash
$gitcheckoutmaster
$gitmerge--squash-ssubtree--no-commitrack_branch
Squashcommit--notupdatingHEAD
Automaticmergewentwell;stoppedbeforecommittingasrequested
Rack—— rackrack_branch
rackrack_branch————diff gitdiff-tree
$gitdiff-tree-prack_branch
rackmaster
$gitdiff-tree-prack_remote/master
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Git
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Chapter7
GitGitGitGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitgitconfigGit
$gitconfig--globaluser.name"JohnDoe"
Git
GitGit /etc/gitconfiggitconfig --systemgitconfig
Git ~/.gitconfig --globalGit
GitGit .git/config .git/config/etc/gitconfig
config
GitGit
$gitconfig--help
gitconfigman
core.editor
GiteditorVi core.editor
$gitconfig--globalcore.editoremacs
editorGitEmacs
commit.template
Git $HOME/.gitmessage.txt
subjectline
whathappened
[ticket:X]
commit.templategitcommitGit commit.template
$gitconfig--globalcommit.template$HOME/.gitmessage.txt
$gitcommit
subjectline
whathappened
[ticket:X]
#Pleaseenterthecommitmessageforyourchanges.Linesstarting
#with'#'willbeignored,andanemptymessageabortsthecommit.
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
#modified:lib/test.rb
#
~
~
".git/COMMIT_EDITMSG"14L,297C
Git
core.pager
core.pagerGit logdiff more less
$gitconfig--globalcore.pager''
user.signingkey
GPGID
$gitconfig--globaluser.signingkey<gpg-key-id>
gittag
$gittag-s<tag-name>
core.excludesfile
.gitignoreGit gitadd core.excludesfileGit
help.autocorrect
Git1.6.1Git1.6
$gitcom
git:'com'isnotagit-command.See'git--help'.
Didyoumeanthis?
commit
help.autocorrect1Git
Git
Git
color.ui
Git color.uitrue
$gitconfig--globalcolor.uitrue
GitfalsealwaysfalsealwaysGitGit1.5.5
color.ui=always --colorGit color.ui=true
color.*
Git truefalsealways
color.branch
color.diff
color.interactive
color.status
diff
$gitconfig--globalcolor.diff.meta“blueblackbold”
normalblackredgreenyellowbluemagentacyanwhitebolddimulblinkreverse
gitconfig
Gitdiff,P4MergePerforce
P4MergeMacLinuxWindows /usr/local/bin
P4Merge
http://www.perforce.com/perforce/downloads/component.html
Mac p4mergemerge extMergep4merge
$cat/usr/local/bin/extMerge
#!/bin/sh
/Applications/p4merge.app/Contents/MacOS/p4merge$*
diff72mergeGitdiff
pathold-fileold-hexold-modenew-filenew-hexnew-mode
old-filenew-filediff
$cat/usr/local/bin/extDiff
#!/bin/sh
[$#-eq7]&&/usr/local/bin/extMerge"$2""$5"
$sudochmod+x/usr/local/bin/extMerge
$sudochmod+x/usr/local/bin/extDiff
merge.toolGit mergetool.*.cmd mergetool.trustExitCode
Git4
$gitconfig--globalmerge.toolextMerge
$gitconfig--globalmergetool.extMerge.cmd\
'extMerge"$BASE""$LOCAL""$REMOTE""$MERGED"'
$gitconfig--globalmergetool.trustExitCodefalse
$gitconfig--globaldiff.externalextDiff
~/.gitconfig
[merge]
tool=extMerge
[mergetool"extMerge"]
cmd=extMerge"$BASE""$LOCAL""$REMOTE""$MERGED"
trustExitCode=false
[diff]
external=extDiff
diff
$gitdiff32d1776b1^32d1776b1
diffGitP4Merge7-1
Figure7-1.P4Merge.
gitmergetoolGitP4Merge
diffmerge extDiffextMergeKDiff3 extMerge
$cat/usr/local/bin/extMerge
#!/bin/sh
/Applications/kdiff3.app/Contents/MacOS/kdiff3$*
GitKDiff3
Gitcmdkdiff3opendifftkdiffmeldxxdiffemergevimdiffgvimdiffKDiff3kdiff3
$gitconfig--globalmerge.toolkdiff3
extMergeextDiffGitKDiff3
WindowsGit
core.autocrlf
WindowsWindowsWindowsMacLinux
GitCRLFLFLFCRLF core.autocrlfWindows trueLFCRLF
$gitconfig--globalcore.autocrlftrue
LinuxMacLFGitCRLF core.autocrlfinputGitCRLFLF
$gitconfig--globalcore.autocrlfinput
WindowsCRLFMacLinuxLF
WindowsWindows false
$gitconfig--globalcore.autocrlffalse
core.whitespace
Git422
2trailing-spacespace-before-tabtrailing-space space-before-tab
2indent-with-non-tabcr-at-eolindent-with-non-tab8 cr-at-eol
core.whitespace - cr-at-eol
$gitconfig--globalcore.whitespace\
trailing-space,space-before-tab,indent-with-non-tab
gitdiffGit gitapplyGit
$gitapply--whitespace=warn<patch>
Git
$gitapply--whitespace=fix<patch>
--whitespace=fixrebaseGit
Git
receive.fsckObjects
GitSHA-1GitGitGit receive.fsckObjects
$gitconfig--systemreceive.fsckObjectstrue
Git
receive.denyNonFastForwards
push -f
receive.denyNonFastForwards
$gitconfig--systemreceive.denyNonFastForwardstrue
receive.denyDeletes
denyNonFastForwardsGit1.6.1 receive.denyDeletestrue
$gitconfig--systemreceive.denyDeletestrue
—
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGitGit
Git hooks .git/hooksGitshellPerl—RubyPythonGit1.6.sampleGit1.6
Git hooksGit
4 pre-commitGit gitcommit--no-verify
prepare-commit-msgSHA-1
commit-msgGit
post-commit gitlog-1HEAD
clone
3e-mail gitame-mail gitformat-patch
applypatch-msgGit
gitampre-applypatch gitam
gitampost-applypatch
pre-rebaseGit pre-rebasenextnext
gitcheckout post-checkout
merge post-mergeGitGit
pre-receivepost-receive
Thefirstscripttorunwhenhandlingapushfromaclientispre-receivearebeingpushedfromstdin;ifitexitsnon-zero,noneofthemareaccepted.Youcanusethishooktodothingslikemakesurenoneoftheupdatedreferencesarenon-fast-forwards;ortocheckthattheuserdoingthepushinghascreate,delete,orpushaccessoraccesstopushupdatestoallthefilesthey’remodifyingwiththepush.
Thepost-receivehookrunsaftertheentireprocessiscompletedandcanbeusedtoupdateotherservicesornotifyusers.Ittakesthesamestdindataasthepre-receivemailingalist,notifyingacontinuousintegrationserver,orupdatingaticket-trackingsystem—youcanevenparsethecommitmessagestoseeifanyticketsneedtobeopened,modified,orclosed.Thisscriptcan’tstopthepushprocess,buttheclientdoesn’tdisconnectuntilithascompleted;so,becarefulwhenyoutrytodoanythingthatmaytakealongtime.
update
Theupdatescriptisverysimilartothepre-receivescript,exceptthatit’srunonceforeachbranchthepusheristryingtoupdate.Ifthepusheristryingtopushtomultiplebranches,once,whereasupdaterunsonceperbranchthey’repushingto.Insteadofreadingfromstdin,thisscripttakesthreearguments:thenameofthereference(branch),theSHA-1thatreferencepointedtobeforethepush,andtheSHA-1theuseristryingtopush.Iftheupdatescriptexitsnon-zero,onlythatreferenceisrejected;otherreferencescanstillbeupdated.
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
AnExampleGit-EnforcedPolicyInthissection,you’llusewhatyou’velearnedtoestablishaGitworkflowthatchecksforacustomcommitmessageformat,enforcesfast-forward-onlypushes,andallowsonlycertainuserstomodifycertainsubdirectoriesinaproject.You’llbuildclientscriptsthathelpthedeveloperknowiftheirpushwillberejectedandserverscriptsthatactuallyenforcethepolicies.
IusedRubytowritethese,bothbecauseit’smypreferredscriptinglanguageandbecauseIfeelit’sthemostpseudocode-lookingofthescriptinglanguages;thusyoushouldbeabletoroughlyfollowthecodeevenifyoudon’tuseRuby.However,anylanguagewillworkfine.AllthesamplehookscriptsdistributedwithGitareineitherPerlorBashscripting,soyoucanalsoseeplentyofexamplesofhooksinthoselanguagesbylookingatthesamples.
Server-SideHook
Alltheserver-sideworkwillgointotheupdatefileinyourhooksdirectory.Theupdatefilerunsonceperbranchbeingpushedandtakesthereferencebeingpushedto,theoldrevisionwherethatbranchwas,andthenewrevisionbeingpushed.YoualsohaveaccesstotheuserdoingthepushingifthepushisbeingrunoverSSH.Ifyou’veallowedeveryonetoconnectwithasingleuser(like“git”)viapublic-keyauthentication,youmayhavetogivethatuserashellwrapperthatdetermineswhichuserisconnectingbasedonthepublickey,andsetanenvironmentvariablespecifyingthatuser.HereIassumetheconnectinguserisinthe$USERenvironmentvariable,soyourupdatescriptbeginsbygatheringalltheinformationyouneed:
#!/usr/bin/envruby
$refname=ARGV[0]
$oldrev=ARGV[1]
$newrev=ARGV[2]
$user=ENV['USER']
puts"EnforcingPolicies...\n(#{$refname})(#{$oldrev[0,6]})(#{$newrev[0,6]})"
Yes,I’musingglobalvariables.Don’tjudgeme—it’seasiertodemonstrateinthismanner.
EnforcingaSpecificCommit-MessageFormat
Yourfirstchallengeistoenforcethateachcommitmessagemustadheretoaparticularformat.Justtohaveatarget,assumethateachmessagehastoincludeastringthatlookslike“ref:1234”becauseyouwanteachcommittolinktoaworkiteminyourticketingsystem.Youmustlookateachcommitbeingpushedup,seeifthatstringisinthecommitmessage,and,ifthestringisabsentfromanyofthecommits,exitnon-zerosothepushisrejected.
YoucangetalistoftheSHA-1valuesofallthecommitsthatarebeingpushedbytakingtheand$oldrevvaluesandpassingthemtoaGitplumbingcommandcalledthegitlogcommand,butbydefaultitprintsoutonlytheSHA-1valuesandnootherinformation.So,togetalistofallthecommitSHAsintroducedbetweenonecommitSHAandanother,youcanrunsomethinglikethis:
$gitrev-list538c33..d14fc7
d14fc7c847ab946ec39590d87783c69b031bdfb7
9f585da4401b0a3999e84113824d15245c13f0be
234071a1be950e2a8d078e6141f5cd20c1e61ad3
dfa04c9ef3d5197182f13fb5b9b1fb7717d2222a
17716ec0f1ff5c77eff40b7fe912f9f6cfd0e475
Youcantakethatoutput,loopthrougheachofthosecommitSHAs,grabthemessageforit,andtestthatmessageagainstaregularexpressionthatlooksforapattern.
Youhavetofigureouthowtogetthecommitmessagefromeachofthesecommitstotest.Togettherawcommitdata,youcanuseanotherplumbingcommandcalledgitcat-fileplumbingcommandsindetailinChapter9;butfornow,here’swhatthatcommandgivesyou:
$gitcat-filecommitca82a6
treecfda3bf379e4f8dba8717dee55aab78aef7f4daf
parent085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
authorScottChacon<[email protected]>1205815931-0700
committerScottChacon<[email protected]>1240030591-0700
changedtheversionnumber
AsimplewaytogetthecommitmessagefromacommitwhenyouhavetheSHA-1valueistogotothefirstblanklineandtakeeverythingafterthat.Youcandosowiththesed
$gitcat-filecommitca82a6|sed'1,/^$/d'
changedtheversionnumber
Youcanusethatincantationtograbthecommitmessagefromeachcommitthatistryingtobepushedandexitifyouseeanythingthatdoesn’tmatch.Toexitthescriptandrejectthepush,exitnon-zero.Thewholemethodlookslikethis:
$regex=/\[ref:(\d+)\]/
#enforcedcustomcommitmessageformat
defcheck_message_format
missed_revs=`gitrev-list#{$oldrev}..#{$newrev}`.split("\n")
missed_revs.eachdo|rev|
message=`gitcat-filecommit#{rev}|sed'1,/^$/d'`
if!$regex.match(message)
puts"[POLICY]Yourmessageisnotformattedcorrectly"
exit1
end
end
end
check_message_format
Puttingthatinyourupdatescriptwillrejectupdatesthatcontaincommitsthathavemessagesthatdon’tadheretoyourrule.
EnforcingaUser-BasedACLSystem
Supposeyouwanttoaddamechanismthatusesanaccesscontrollist(ACL)thatspecifieswhichusersareallowedtopushchangestowhichpartsofyourprojects.Somepeoplehavefullaccess,andothersonlyhaveaccesstopushchangestocertainsubdirectoriesorspecificfiles.Toenforcethis,you’llwritethoserulestoafilenamedaclthatlivesinyourbareGitrepositoryontheserver.You’llhavethehooklookatthoserules,seewhatfilesarebeingintroducedforallthecommitsbeingpushed,anddeterminewhethertheuserdoingthepushhasaccesstoupdateallthosefiles.
Thefirstthingyou’lldoiswriteyourACL.Hereyou’lluseaformatverymuchliketheCVSACL
mechanism:itusesaseriesoflines,wherethefirstfieldisavailorunavaildelimitedlistoftheuserstowhichtheruleapplies,andthelastfieldisthepathtowhichtheruleapplies(blankmeaningopenaccess).Allofthesefieldsaredelimitedbyapipe(
Inthiscase,youhaveacoupleofadministrators,somedocumentationwriterswithaccesstothedirectory,andonedeveloperwhoonlyhasaccesstothelibandtestslookslikethis:
avail|nickh,pjhyett,defunkt,tpw
avail|usinclair,cdickens,ebronte|doc
avail|schacon|lib
avail|schacon|tests
Youbeginbyreadingthisdataintoastructurethatyoucanuse.Inthiscase,tokeeptheexamplesimple,you’llonlyenforcetheavaildirectives.Hereisamethodthatgivesyouanassociativearraywherethekeyistheusernameandthevalueisanarrayofpathstowhichtheuserhaswriteaccess:
defget_acl_access_data(acl_file)
#readinACLdata
acl_file=File.read(acl_file).split("\n").reject{|line|line==''}
access={}
acl_file.eachdo|line|
avail,users,path=line.split('|')
nextunlessavail=='avail'
users.split(',').eachdo|user|
access[user]||=[]
access[user]<<path
end
end
access
end
OntheACLfileyoulookedatearlier,thisget_acl_access_datamethodreturnsadatastructurethatlookslikethis:
{"defunkt"=>[nil],
"tpw"=>[nil],
"nickh"=>[nil],
"pjhyett"=>[nil],
"schacon"=>["lib","tests"],
"cdickens"=>["doc"],
"usinclair"=>["doc"],
"ebronte"=>["doc"]}
Nowthatyouhavethepermissionssortedout,youneedtodeterminewhatpathsthecommitsbeingpushedhavemodified,soyoucanmakesuretheuserwho’spushinghasaccesstoallofthem.
Youcanprettyeasilyseewhatfileshavebeenmodifiedinasinglecommitwiththetothegitlogcommand(mentionedbrieflyinChapter2):
$gitlog-1--name-only--pretty=format:''9f585d
README
lib/test.rb
IfyouusetheACLstructurereturnedfromtheget_acl_access_datamethodandcheckitagainstthelistedfilesineachofthecommits,youcandeterminewhethertheuserhasaccesstopushalloftheircommits:
#onlyallowscertainuserstomodifycertainsubdirectoriesinaproject
defcheck_directory_perms
access=get_acl_access_data('acl')
#seeifanyoneistryingtopushsomethingtheycan't
new_commits=`gitrev-list#{$oldrev}..#{$newrev}`.split("\n")
new_commits.eachdo|rev|
files_modified=`gitlog-1--name-only--pretty=format:''#{rev}`.split("\n")
files_modified.eachdo|path|
nextifpath.size==0
has_file_access=false
access[$user].eachdo|access_path|
if!access_path#userhasaccesstoeverything
||(path.index(access_path)==0)#accesstothispath
has_file_access=true
end
end
if!has_file_access
puts"[POLICY]Youdonothaveaccesstopushto#{path}"
exit1
end
end
end
end
check_directory_perms
Mostofthatshouldbeeasytofollow.Yougetalistofnewcommitsbeingpushedtoyourserverwithrev-list.Then,foreachofthose,youfindwhichfilesaremodifiedandmakesuretheuserwho’s
pushinghasaccesstoallthepathsbeingmodified.OneRubyismthatmaynotbeclearispath.index(access_path)==0,whichistrueifpathbeginswithaccess_pathaccess_pathisnotjustinoneoftheallowedpaths,butanallowedpathbeginswitheachaccessedpath.
Nowyouruserscan’tpushanycommitswithbadlyformedmessagesorwithmodifiedfilesoutsideoftheirdesignatedpaths.
EnforcingFast-Forward-OnlyPushes
Theonlythingleftistoenforcefast-forward-onlypushes.InGitversions1.6ornewer,youcansetthereceive.denyDeletesandreceive.denyNonFastForwardssettings.ButenforcingthiswithahookwillworkinolderversionsofGit,andyoucanmodifyittodosoonlyforcertainusersorwhateverelseyoucomeupwithlater.
Thelogicforcheckingthisistoseeifanycommitsarereachablefromtheolderrevisionthataren’treachablefromthenewerone.Iftherearenone,thenitwasafast-forwardpush;otherwise,youdenyit:
#enforcesfast-forwardonlypushes
defcheck_fast_forward
missed_refs=`gitrev-list#{$newrev}..#{$oldrev}`
missed_ref_count=missed_refs.split("\n").size
ifmissed_ref_count>0
puts"[POLICY]Cannotpushanonfast-forwardreference"
exit1
end
end
check_fast_forward
Everythingissetup.Ifyourunchmodu+x.git/hooks/update,whichisthefileyouintowhichyoushouldhaveputallthiscode,andthentrytopushanon-fast-forwardedreference,yougetsomethinglikethis:
$gitpush-foriginmaster
Countingobjects:5,done.
Compressingobjects:100%(3/3),done.
Writingobjects:100%(3/3),323bytes,done.
Total3(delta1),reused0(delta0)
Unpackingobjects:100%(3/3),done.
EnforcingPolicies...
(refs/heads/master)(8338c5)(c5b616)
[POLICY]Cannotpushanon-fast-forwardreference
error:hooks/updateexitedwitherrorcode1
error:hookdeclinedtoupdaterefs/heads/master
Togit@gitserver:project.git
![remoterejected]master->master(hookdeclined)
error:failedtopushsomerefsto'git@gitserver:project.git'
Thereareacoupleofinterestingthingshere.First,youseethiswherethehookstartsrunning.
EnforcingPolicies...
(refs/heads/master)(fb8c72)(c56860)
Noticethatyouprintedthatouttostdoutattheverybeginningofyourupdatescript.It’simportanttonotethatanythingyourscriptprintstostdoutwillbetransferredtotheclient.
Thenextthingyou’llnoticeistheerrormessage.
[POLICY]Cannotpushanonfast-forwardreference
error:hooks/updateexitedwitherrorcode1
error:hookdeclinedtoupdaterefs/heads/master
Thefirstlinewasprintedoutbyyou,theothertwowereGittellingyouthattheupdatescriptexitednon-zeroandthatiswhatisdecliningyourpush.Lastly,youhavethis:
Togit@gitserver:project.git
![remoterejected]master->master(hookdeclined)
error:failedtopushsomerefsto'git@gitserver:project.git'
You’llseearemoterejectedmessageforeachreferencethatyourhookdeclined,andittellsyouthatitwasdeclinedspecificallybecauseofahookfailure.
Furthermore,iftherefmarkerisn’tthereinanyofyourcommits,you’llseetheerrormessageyou’reprintingoutforthat.
[POLICY]Yourmessageisnotformattedcorrectly
Orifsomeonetriestoeditafiletheydon’thaveaccesstoandpushacommitcontainingit,theywillseesomethingsimilar.Forinstance,ifadocumentationauthortriestopushacommitmodifyingsomething
inthelibdirectory,theysee
[POLICY]Youdonothaveaccesstopushtolib/test.rb
That’sall.Fromnowon,aslongasthatupdatescriptisthereandexecutable,yourrepositorywillneverberewoundandwillneverhaveacommitmessagewithoutyourpatterninit,andyouruserswillbesandboxed.
Client-SideHooks
Thedownsidetothisapproachisthewhiningthatwillinevitablyresultwhenyourusers’commitpushesarerejected.Havingtheircarefullycraftedworkrejectedatthelastminutecanbeextremelyfrustratingandconfusing;andfurthermore,theywillhavetoedittheirhistorytocorrectit,whichisn’talwaysforthefaintofheart.
Theanswertothisdilemmaistoprovidesomeclient-sidehooksthatuserscanusetonotifythemwhenthey’redoingsomethingthattheserverislikelytoreject.Thatway,theycancorrectanyproblemsbeforecommittingandbeforethoseissuesbecomemoredifficulttofix.Becausehooksaren’ttransferredwithacloneofaproject,youmustdistributethesescriptssomeotherwayandthenhaveyouruserscopythemtotheir.git/hooksdirectoryandmakethemexecutable.Youcandistributethesehookswithintheprojectorinaseparateproject,butthereisnowaytosetthemupautomatically.
Tobegin,youshouldcheckyourcommitmessagejustbeforeeachcommitisrecorded,soyouknowtheserverwon’trejectyourchangesduetobadlyformattedcommitmessages.Todothis,youcanaddthecommit-msghook.Ifyouhaveitreadthemessagefromthefilepassedasthefirstargumentandcomparethattothepattern,youcanforceGittoabortthecommitifthereisnomatch:
#!/usr/bin/envruby
message_file=ARGV[0]
message=File.read(message_file)
$regex=/\[ref:(\d+)\]/
if!$regex.match(message)
puts"[POLICY]Yourmessageisnotformattedcorrectly"
exit1
end
Ifthatscriptisinplace(in.git/hooks/commit-msg)andexecutable,andyoucommitwithamessagethatisn’tproperlyformatted,youseethis:
$gitcommit-am'test'
[POLICY]Yourmessageisnotformattedcorrectly
Nocommitwascompletedinthatinstance.However,ifyourmessagecontainstheproperpattern,Gitallowsyoutocommit:
$gitcommit-am'test[ref:132]'
[mastere05c914]test[ref:132]
1fileschanged,1insertions(+),0deletions(-)
Next,youwanttomakesureyouaren’tmodifyingfilesthatareoutsideyourACLscope.Ifyourproject’s.gitdirectorycontainsacopyoftheACLfileyouusedpreviously,thenthefollowingwillenforcethoseconstraintsforyou:
#!/usr/bin/envruby
$user=ENV['USER']
#[insertacl_access_datamethodfromabove]
#onlyallowscertainuserstomodifycertainsubdirectoriesinaproject
defcheck_directory_perms
access=get_acl_access_data('.git/acl')
files_modified=`gitdiff-index--cached--name-onlyHEAD`.split("\n")
files_modified.eachdo|path|
nextifpath.size==0
has_file_access=false
access[$user].eachdo|access_path|
if!access_path||(path.index(access_path)==0)
has_file_access=true
end
if!has_file_access
puts"[POLICY]Youdonothaveaccesstopushto#{path}"
exit1
end
end
end
check_directory_perms
Thisisroughlythesamescriptastheserver-sidepart,butwithtwoimportantdifferences.First,theACLfileisinadifferentplace,becausethisscriptrunsfromyourworkingdirectory,notfromyourGitdirectory.YouhavetochangethepathtotheACLfilefromthis
access=get_acl_access_data('acl')
tothis:
access=get_acl_access_data('.git/acl')
Theotherimportantdifferenceisthewayyougetalistingofthefilesthathavebeenchanged.Becausetheserver-sidemethodlooksatthelogofcommits,and,atthispoint,thecommithasn’tbeenrecordedyet,youmustgetyourfilelistingfromthestagingareainstead.Insteadof
files_modified=`gitlog-1--name-only--pretty=format:''#{ref}`
youhavetouse
files_modified=`gitdiff-index--cached--name-onlyHEAD`
Butthosearetheonlytwodifferences—otherwise,thescriptworksthesameway.Onecaveatisthatitexpectsyoutoberunninglocallyasthesameuseryoupushastotheremotemachine.Ifthatisdifferent,youmustsetthe$uservariablemanually.
Thelastthingyouhavetodoischeckthatyou’renottryingtopushnon-fast-forwardedreferences,butthatisabitlesscommon.Togetareferencethatisn’tafast-forward,youeitherhavetorebasepastacommityou’vealreadypusheduportrypushingadifferentlocalbranchuptothesameremotebranch.
Becausetheserverwilltellyouthatyoucan’tpushanon-fast-forwardanyway,andthehookpreventsforcedpushes,theonlyaccidentalthingyoucantrytocatchisrebasingcommitsthathavealreadybeenpushed.
Hereisanexamplepre-rebasescriptthatchecksforthat.Itgetsalistofallthecommitsyou’reabouttorewriteandcheckswhethertheyexistinanyofyourremotereferences.Ifitseesonethatisreachablefromoneofyourremotereferences,itabortstherebase:
#!/usr/bin/envruby
base_branch=ARGV[0]
ifARGV[1]
topic_branch=ARGV[1]
else
topic_branch="HEAD"
end
target_shas=`gitrev-list#{base_branch}..#{topic_branch}`.split("\n")
remote_refs=`gitbranch-r`.split("\n").map{|r|r.strip}
target_shas.eachdo|sha|
remote_refs.eachdo|remote_ref|
shas_pushed=`gitrev-list^#{sha}^@refs/remotes/#{remote_ref}`
ifshas_pushed.split(“\n”).include?(sha)
puts"[POLICY]Commit#{sha}hasalreadybeenpushedto#{remote_ref}"
exit1
end
end
end
Thisscriptusesasyntaxthatwasn’tcoveredintheRevisionSelectionsectionofChapter6.Yougetalistofcommitsthathavealreadybeenpushedupbyrunningthis:
gitrev-list^#{sha}^@refs/remotes/#{remote_ref}
TheSHA^@syntaxresolvestoalltheparentsofthatcommit.You’relookingforanycommitthatisreachablefromthelastcommitontheremoteandthatisn’treachablefromanyparentofanyoftheSHAsyou’retryingtopushup—meaningit’safast-forward.
Themaindrawbacktothisapproachisthatitcanbeveryslowandisoftenunnecessary—ifyoudon’ttrytoforcethepushwith-f,theserverwillwarnyouandnotacceptthepush.However,it’saninterestingexerciseandcanintheoryhelpyouavoidarebasethatyoumightlaterhavetogobackandfix.
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
SummaryYou’vecoveredmostofthemajorwaysthatyoucancustomizeyourGitclientandservertobestfityourworkflowandprojects.You’velearnedaboutallsortsofconfigurationsettings,file-basedattributes,andeventhooks,andyou’vebuiltanexamplepolicy-enforcingserver.YoushouldnowbeabletomakeGitfitnearlyanyworkflowyoucandreamup.
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitSubversionSubversionSubversionCVS
Git gitsvnSubversionGitSubversionGitSubversionSubversionGitGitSubversionDVCS,DistributedVCS
gitsvn
GitSubversion gitsvn
gitsvnSubversionGitGit
GitGitSubersionSVNGitSVN——
SVN svnsyncSubversion
Subversion
$mkdir/tmp/test-svn
$svnadmincreate/tmp/test-svn
revprop——0pre-revprop-change
$cat/tmp/test-svn/hooks/pre-revprop-change
#!/bin/sh
exit0;
$chmod+x/tmp/test-svn/hooks/pre-revprop-change
svnsyncinit
$svnsyncinitfile:///tmp/test-svnhttp://progit-example.googlecode.com/svn/
$svnsyncsyncfile:///tmp/test-svn
Committedrevision1.
Copiedpropertiesforrevision1.
Committedrevision2.
Copiedpropertiesforrevision2.
Committedrevision3.
...
100Subversion——
Subversion gitsvncloneSubversionGitSubversionfile:///tmp/test-svnSubversionURL
$gitsvnclonefile:///tmp/test-svn-Ttrunk-bbranches-ttags
InitializedemptyGitrepositoryin/Users/schacon/projects/testsvnsync/svn/.git/
r1=b4e387bc68740b5af56c2a5faf4003ae42bd135c(trunk)
Am4/acx_pthread.m4
Am4/stl_hash.m4
...
r75=d1957f3b307922124eec6314e15bcda59e3d9610(trunk)
Foundpossiblebranchpoint:file:///tmp/test-svn/trunk=>\
file:///tmp/test-svn/branches/my-calc-branch,75
Foundbranchparent:(my-calc-branch)d1957f3b307922124eec6314e15bcda59e3d9610
Followingparentwithdo_switch
Successfullyfollowedparent
r76=8624824ecc0badd73f40ea2f01fce51894189b01(my-calc-branch)
CheckedoutHEAD:
file:///tmp/test-svn/branches/my-calc-branchr76
URL—— gitsvninit gitsvnfetch75Git
-Ttrunk-bbranches-ttagsGitSubversion(trunkmastersStandardlayout
$gitsvnclonefile:///tmp/test-svn-s
Git
$gitbranch-a
*master
my-calc-branch
tags/2.0.2
tags/release-2.0.1
tags/release-2.0.2
tags/release-2.0.2rc1
trunk
Git origin/[branch]—— gitsvnGit show-ref
$gitshow-ref
1cbd4904d9982f386d87f88fce1c24ad7c0f0471refs/heads/master
aee1ecc26318164f355a883f5d99cff0c852d3c4refs/remotes/my-calc-branch
03d09b0e2aad427e34a6d50ff147128e76c0e0f5refs/remotes/tags/2.0.2
50d02cc0adc9da4319eeba0900430ba219b9c376refs/remotes/tags/release-2.0.1
4caaa711a50c77879a91b8b90380060f672745cbrefs/remotes/tags/release-2.0.2
1c4cb508144c513ff1214c3488abe66dcb92916frefs/remotes/tags/release-2.0.2rc1
1cbd4904d9982f386d87f88fce1c24ad7c0f0471refs/remotes/trunk
Git
$gitshow-ref
83e38c7a0af325a9722f2fdc56b10188806d83a1refs/heads/master
3e15e38c198baac84223acfc6224bb8b99ff2281refs/remotes/gitserver/master
0a30dd3b0c795b80212ae723640d4e5d48cabdffrefs/remotes/origin/master
25812380387fdd55f916652be4881c6f11600d6frefs/remotes/origin/testing
gitserver master origin master testing
gitsvnSubversion)GitSubversiontags
Subversion
GitSVNGitSubversion
$gitcommit-am'Addinggit-svninstructionstotheREADME'
[master97031e5]Addinggit-svninstructionstotheREADME
1fileschanged,1insertions(+),1deletions(-)
Subversion——SubversionSubversion gitsvndcommit
$gitsvndcommit
Committingtofile:///tmp/test-svn/trunk...
MREADME.txt
Committedr79
MREADME.txt
r79=938b1a547c2cc92033b74d32030e86468294a5c8(trunk)
NochangesbetweencurrentHEADandrefs/remotes/trunk
Resettingtothelatestrefs/remotes/trunk
SubversioncommitSubversionGitcommitcommitSHA-1GitSubversioncommit
$gitlog-1
commit938b1a547c2cc92033b74d32030e86468294a5c8
Author:schacon<schacon@4c93b258-373f-11de-be05-5f7a86268029>
Date:SatMay222:06:442009+0000
Addinggit-svninstructionstotheREADME
git-svn-id:file:///tmp/test-svn/trunk@794c93b258-373f-11de-be05-5f7a86268029
97031e5SHA-1 938b1a5GitSubversionSubversion
gitsvn
$gitsvndcommit
Committingtofile:///tmp/test-svn/trunk...
Mergeconflictduringcommit:Yourfileordirectory'README.txt'isprobably\
out-of-date:resourceoutofdate;tryupdatingat/Users/schacon/libexec/git-\
core/git-svnline482
gitsvnrebase
$gitsvnrebase
MREADME.txt
r80=ff829ab914e8775c7c025d741beb3d523ee30bc4(trunk)
First,rewindingheadtoreplayyourworkontopofit...
Applying:firstuserchange
dcommit
$gitsvndcommit
Committingtofile:///tmp/test-svn/trunk...
MREADME.txt
Committedr81
MREADME.txt
r81=456cbe6337abe49154db70106d1836bc1332deed(trunk)
NochangesbetweencurrentHEADandrefs/remotes/trunk
Resettingtothelatestrefs/remotes/trunk
Git gitsvn dcommit
$gitsvndcommit
Committingtofile:///tmp/test-svn/trunk...
Mconfigure.ac
Committedr84
Mautogen.sh
r83=8aa54a74d452f82eee10076ab2584c1fc424853b(trunk)
Mconfigure.ac
r84=cdbac939211ccb18aa744e581e46563af5d962d0(trunk)
W:d2f23b80f67aaaa1f6f5aaef48fce3263ac71a92andrefs/remotes/trunkdiffer,\
usingrebase:
:100755100755efa5a59965fbbb5b2b0a12890f1b351bb5493c18\
015e4c98c482f0fa71e4d5434338014530b37fa6Mautogen.sh
First,rewindingheadtoreplayyourworkontopofit...
Nothingtodo.
Git——GitSVN
Subversion sitsvnfetch gitsvnrebase
$gitsvnrebase
Mgenerate_descriptor_proto.sh
r82=bd16df9173e424c6f52c337ab6efa7f7643282f1(trunk)
First,rewindingheadtoreplayyourworkontopofit...
Fast-forwardedmastertorefs/remotes/trunk.
gitsvnrebase gitsvnrebase——
Git
GitgitsvnSubversionSubversionGitGitsvnSubversioncommit
experiment master dcommit
$gitsvndcommit
Committingtofile:///tmp/test-svn/trunk...
MCHANGES.txt
Committedr85
MCHANGES.txt
r85=4bfebeec434d156c36f2bcd18f4e3d97dc3269a2(trunk)
NochangesbetweencurrentHEADandrefs/remotes/trunk
Resettingtothelatestrefs/remotes/trunk
COPYING.txt:locallymodified
INSTALL.txt:locallymodified
MCOPYING.txt
MINSTALL.txt
Committedr86
MINSTALL.txt
MCOPYING.txt
r86=2647f6b86ccfcaad4ec58c520e369ec81f7c283c(trunk)
NochangesbetweencurrentHEADandrefs/remotes/trunk
Resettingtothelatestrefs/remotes/trunk
dcommitGit experimentcommit——SVNcommit
commit
Subversion
SubversionGitgitsvnSubversion
SVN
Subversion gitsvnbranch[] TocreateanewbranchinSubversion,yourunbranch[branchname]:
$gitsvnbranchopera
Copyingfile:///tmp/test-svn/trunkatr87tofile:///tmp/test-svn/branches/opera...
Foundpossiblebranchpoint:file:///tmp/test-svn/trunk=>\
file:///tmp/test-svn/branches/opera,87
Foundbranchparent:(opera)1f6bfe471083cbca06ac8d4176f7ad4de0d62e5f
Followingparentwithdo_switch
Successfullyfollowedparent
r89=9b6fe0b90c5c9adf9165f700897518dbc54a7cbf(opera)
Subversion svncopytrunkbranches/operaSubversion
GitSubversiondcommit—— git-svn-id
Subversioncommit dcommit opera
$gitbranchoperaremotes/opera
opera trunk master gitmerge -m Mergebranchopera
gitmergeSubversionGitGitcommitSubversioncommitGitSubversion
Subversion
gitsvnSubversionGitSubversion
SVN
SubversionSVN gitsvnlogSVN
$gitsvnlog
------------------------------------------------------------------------
r87|schacon|2009-05-0216:07:37-0700(Sat,02May2009)|2lines
autogenchange
------------------------------------------------------------------------
r86|schacon|2009-05-0216:00:21-0700(Sat,02May2009)|2lines
Mergebranch'experiment'
------------------------------------------------------------------------
r85|schacon|2009-05-0216:00:09-0700(Sat,02May2009)|2lines
updatedthechangelog
gitsvnlog svnlogSubversionSubversioncommitdcommitGitSubversionSubversion
SVN
gitsvnlog gitlog svnannotate gitsvnblame[]
$gitsvnblameREADME.txt
2temporalProtocolBuffers-Google'sdatainterchangeformat
2temporalCopyright2008GoogleInc.
2temporalhttp://code.google.com/apis/protocolbuffers/
2temporal
22temporalC++Installation-Unix
22temporal=======================
2temporal
79schaconCommittingingit-svn.
78schacon
2temporalTobuildandinstalltheC++ProtocolBufferruntimeandtheProtocol
2temporalBuffercompiler(protoc)executethefollowing:
2temporal
GitSubversion
SVN
gitsvninfo svninfo
$gitsvninfo
Path:.
URL:https://schacon-test.googlecode.com/svn/trunk
RepositoryRoot:https://schacon-test.googlecode.com/svn
RepositoryUUID:4c93b258-373f-11de-be05-5f7a86268029
Revision:87
NodeKind:directory
Schedule:normal
LastChangedAuthor:schacon
LastChangedRev:87
LastChangedDate:2009-05-0216:07:37-0700(Sat,02May2009)
blame logSubversion
Subversion
svn:ignoreSubversion .gitignore gitsvn gitsvncreate-ignore
.gitignore
gitsvnshow-ignore .gitignore
$gitsvnshow-ignore>.git/info/exclude
.gitignoreSubversionGit .gitignore
Git-Svn
gitsvnSubversionSubversionGit
gitmergecommitGit git-svn-id pre-receive git-svn-idcommit
SubversionGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGitGit
——SubversionPerforce——GitGit
Subversion
gitsvn gitsvncloneSubversionGitserverSubversion
Subversion schacon blame gitsvnlog
Git user.txt
schacon=ScottChacon<[email protected]>
selse=SomeoNelse<[email protected]>
SVN
$svnlog--xml|grepauthor|sort-u|perl-pe's/.>(.?)<./$1=/'
XML——XML grepsort perl.user.txtGit
gitsvn clone init --no-metadata gitsvnSubversion
$git-svnclonehttp://my-project.googlecode.com/svn/\
--authors-file=users.txt--no-metadata-smy_project
my_projectSubversioncommit
commit37efa680e8473b615de980fa935944215428a35a
Author:schacon<schacon@4c93b258-373f-11de-be05-5f7a86268029>
Date:SunMay300:12:222009+0000
fixedinstall-gototrunk
git-svn-id:https://my-project.googlecode.com/svn/trunk@944c93b258-373f-11de-
be05-5f7a86268029
commit03a8785f44c8ea5cdb0e8834b7c8e6c469be2ff2
Author:ScottChacon<[email protected]>
Date:SunMay300:12:222009+0000
fixedinstall-gototrunk
git-svn-id
post-import gitsvn
Git
$cp-Rf.git/refs/remotes/tags/*.git/refs/tags/
$rm-Rf.git/refs/remotes/tags
tag/
refs/remotes
$cp-Rf.git/refs/remotes/*.git/refs/heads/
$rm-Rf.git/refs/remotes
GitGitGit
$gitpushorigin--all
Git
Perforce
Perforce.GitPerforce contrib—— gitsvnGitgit.kernel.org
$gitclonegit://git.kernel.org/pub/scm/git/git.git
$cdgit/contrib/fast-import
fast-import git-p4PythonPython p4PerforcePerforcePublicDepotPerforceJamP4PORTexportPerforce
$exportP4PORT=public.perforce.com:1666
git-p4clonePerforceJam
$git-p4clone//public/jam/src@all/opt/p4import
Importingfrom//public/jam/src@allinto/opt/p4import
ReinitializedexistingGitrepositoryin/opt/p4import/.git/
Importdestination:refs/remotes/p4/master
Importingrevision4409(100%)
/opt/p4import gitlog
$gitlog-2
commit1fd4ec126171790efd2db83548b85b1bbbc07dc2
Author:Perforcestaff<[email protected]>
Date:ThuAug1910:18:452004-0800
Drop'rc3'monikerofjam-2.5.Foldedrc2andrc3RELNOTESinto
themainpartofthedocument.Builtnewtar/zipballs.
Only16monthslater.
[git-p4:depot-paths="//public/jam/src/":change=4409]
commitca8870db541a23ed867f38847eda65bf4363371d
Author:RichardGeiger<[email protected]>
Date:TueApr2220:51:342003-0800
Updatederivedjamgram.c
[git-p4:depot-paths="//public/jam/src/":change=3108]
commit git-p4Perforce—— gitfilter-branch
$gitfilter-branch--msg-filter'
sed-e"/^\[git-p4:/d"
'
Rewrite1fd4ec126171790efd2db83548b85b1bbbc07dc2(123/123)
Ref'refs/heads/master'wasrewritten
gitlogcommitSHA-1 git-p4
$gitlog-2
commit10a16d60cffca14d454a15c6164378f4082bc5b0
Author:Perforcestaff<[email protected]>
Date:ThuAug1910:18:452004-0800
Drop'rc3'monikerofjam-2.5.Foldedrc2andrc3RELNOTESinto
themainpartofthedocument.Builtnewtar/zipballs.
Only16monthslater.
commit2b6c6db311dd76c34c66ec1c40a49405e6b527b2
Author:RichardGeiger<[email protected]>
Date:TueApr2220:51:342003-0800
Updatederivedjamgram.c
Git
SubversionPerforce——CVSClearCaseVisualSourceSafeimportGitGitGit gitfast-import
back_YY_MM_DDGit
$ls/opt/import_from
back_2009_01_02
back_2009_01_04
back_2009_01_14
back_2009_02_03
current
GitGitGitcommit fast-importcommitcommitcommit
“Git”Ruby——WindowscarriagereturnsWindows\r——Gitfast-importLFWindowsCRLF
commit
last_mark=nil
#
Dir.chdir(ARGV[0])do
Dir.glob("*").eachdo|dir|
nextifFile.file?(dir)
#
Dir.chdir(dir)do
last_mark=print_export(dir,last_mark)
end
end
end
print_export”mark” fast-importcommitcommitcommit print_export
mark=convert_dir_to_mark(dir)
$marks=[]
defconvert_dir_to_mark(dir)
if!$marks.include?(dir)
$marks<<dir
end
($marks.index(dir)+1).to_s
end
commit print_export
date=convert_dir_to_date(dir)
convert_dir_to_date
defconvert_dir_to_date(dir)
ifdir=='current'
returnTime.now().to_i
else
dir=dir.gsub('back_','')
(year,month,day)=dir.split('_')
returnTime.local(year,month,day).to_i
end
end
$author='ScottChacon<[email protected]>'
commitcommit
#
puts'commitrefs/heads/master'
puts'mark:'+mark
puts"committer#{$author}#{date}-0700"
export_data('importedfrom'+dir)
puts'from:'+last_markiflast_mark
-0700
data(size)\n(contents)
data export_data
defexport_data(string)
print"data#{string.size}\n#{string}"
end
—— deleeallGit
puts'deleteall'
Dir.glob("**/*").eachdo|file|nextif!File.file?(file)
inline_data(file)
end
commitcommitfast-import——Git
M644inlinepath/to/file
data(size)
(filecontents)
644755inline inline_data
definline_data(file,code='M',mode='644')
content=File.read(file)
puts"#{code}#{mode}inline#{file}"
export_data(content)
end
export_data
returnmark
WindowsWindowsCRLFGitfast-importLFgitfast-importrubyLFCRLF
$stdout.binmode
$rubyimport.rb/opt/import_from
commitrefs/heads/master
mark:1
committerScottChacon<[email protected]>1230883200-0700
data29
importedfromback_2009_01_02deleteall
M644inlinefile.rb
data12
versiontwo
commitrefs/heads/master
mark:2
committerScottChacon<[email protected]>1231056000-0700
data29
importedfromback_2009_01_04from:1
deleteall
M644inlinefile.rb
data14
versionthree
M644inlinenew.rb
data16
newversionone
(...)
gitfast-import gitinit
$gitinit
InitializedemptyGitrepositoryin/opt/import_to/.git/
$rubyimport.rb/opt/import_from|gitfast-import
git-fast-importstatistics:
---------------------------------------------------------------------
Alloc'dobjects:5000
Totalobjects:18(1duplicates)
blobs:7(1duplicates0deltas)
trees:6(0duplicates1deltas)
commits:5(0duplicates0deltas)
tags:0(0duplicates0deltas)
Totalbranches:1(1loads)
marks:1024(5unique)
atoms:3
Memorytotal:2255KiB
pools:2098KiB
objects:156KiB
---------------------------------------------------------------------
pack_report:getpagesize()=4096
pack_report:core.packedGitWindowSize=33554432
pack_report:core.packedGitLimit=268435456
pack_report:pack_used_ctr=9
pack_report:pack_mmap_calls=5
pack_report:pack_open_windows=1/1
pack_report:pack_mapped=1356/1356
---------------------------------------------------------------------
518 gitlog
$gitlog-2
commit10bfe7d22ce15ee25b60a824c8982157ca593d41
Author:ScottChacon<[email protected]>
Date:SunMay312:57:392009-0700
importedfromcurrent
commit7e519590de754d079dd73b44d695a42c9d2df452
Author:ScottChacon<[email protected]>
Date:TueFeb301:00:002009-0700
importedfromback_2009_02_03
——Git—— master
$ls
$gitreset--hardmaster
HEADisnowat10bfe7dimportedfromcurrent
$ls
file.rblib
fast-import——Git contib/fast-import git-p4
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
SubversionGitGitGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Chapter9
GitGitGit
Git(content-addressable)VCS
Git(1.5)VCSUIGitUI
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
(Plumbing)(Porcelain) checkout,branch,remote30GitGitVCSVCSUNIX“plumbing”“porcelain”
GitGit
gitinitGit .gitGit
$ls
HEAD
branches/
config
description
hooks/
index
info/
objects/
refs/
gitinitGit branches descriptionGitWeb.gitignore(ignoredpatterns) hooks
HEAD index objects refsGit objects refs()Git
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGit
Gitkey-value hash-object .gitGit
$mkdirtest
$cdtest
$gitinit
InitializedemptyGitrepositoryin/tmp/test/.git/
$find.git/objects
.git/objects
.git/objects/info
.git/objects/pack
$find.git/objects-typef
$
Git objects pack infoGit
$echo'testcontent'|githash-object-w--stdin
d670460b4b4aece5915caf5c68d12f560a9fe3e4
-w hash-object() --stdin(stdin)40SHA-1──Git
$find.git/objects-typef
.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4
objectsGit──SHA-1()38()
cat-fileGit -p
$gitcat-file-pd670460b4b4aece5915caf5c68d12f560a9fe3e4
testcontent
Git
$echo'version1'>test.txt
$githash-object-wtest.txt
83baae61804e65cc73a7201a7252750c76066a30
$echo'version2'>test.txt
$githash-object-wtest.txt
1f7a7a472abf3dd9643fd615f6da379c4acb3e3a
$find.git/objects-typef
.git/objects/1f/7a7a472abf3dd9643fd615f6da379c4acb3e3a
.git/objects/83/baae61804e65cc73a7201a7252750c76066a30
.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4
$gitcat-file-p83baae61804e65cc73a7201a7252750c76066a30>test.txt
$cattest.txt
version1
$gitcat-file-p1f7a7a472abf3dd9643fd615f6da379c4acb3e3a>test.txt
$cattest.txt
version2
SHA-1blobSHA-1 cat-file-tGit
$gitcat-file-t1f7a7a472abf3dd9643fd615f6da379c4acb3e3a
blob
tree()
treetreeGitUNIXtreeblobtreeUNIXblobinodestreetreeblobtreeSHA-1(mode)simplegittree
$gitcat-file-pmaster^{tree}
100644bloba906cb2a4a904a152e80877d4088654daad0c859README
100644blob8f94139338f9404f26296befa88755fc2598c289Rakefile
040000tree99f1a6d12cb4b6f19c8655fca46c3ecf317074e0lib
master^{tree} branchtree libblobtree
$gitcat-file-p99f1a6d12cb4b6f19c8655fca46c3ecf317074e0
100644blob47c6340d6459e05787f644c2447d2595f5d3a54bsimplegit.rb
Git9-1
Figure9-1.Git
treeGitindextreetreeindexplumbing update-index
──indextest.txt()
$gitupdate-index--add--cacheinfo100644\
83baae61804e65cc73a7201a7252750c76066a30test.txt
100644 100755 120000UNIX──Git(blobs)()
write-treetree -w──tree write-treeindextree
$gitwrite-tree
d8329fc1cc938780ffdd9f94e0d364e0ea74f579
$gitcat-file-pd8329fc1cc938780ffdd9f94e0d364e0ea74f579
100644blob83baae61804e65cc73a7201a7252750c76066a30test.txt
tree
$gitcat-file-td8329fc1cc938780ffdd9f94e0d364e0ea74f579
tree
test.txttree
$echo'newfile'>new.txt
$gitupdate-indextest.txt
$gitupdate-index--addnew.txt
test.txtnew.txt()tree(indextree)
$gitwrite-tree
0155eb4229851634a0f03eb265b69f5a2d56f341
$gitcat-file-p0155eb4229851634a0f03eb265b69f5a2d56f341
100644blobfa49b077972391ad58037050f2a75f74e3671e92new.txt
100644blob1f7a7a472abf3dd9643fd615f6da379c4acb3e3atest.txt
treetest.txtSHA“”( 1f7a7a)treetree read-tree
-prefix read-treetreetree
$gitread-tree--prefix=bakd8329fc1cc938780ffdd9f94e0d364e0ea74f579
$gitwrite-tree
3c4e9cd789d88d8d89c1073707c3585e41b0e614
$gitcat-file-p3c4e9cd789d88d8d89c1073707c3585e41b0e614
040000treed8329fc1cc938780ffdd9f94e0d364e0ea74f579bak
100644blobfa49b077972391ad58037050f2a75f74e3671e92new.txt
100644blob1f7a7a472abf3dd9643fd615f6da379c4acb3e3atest.txt
tree baktest.txtGit9-2
Figure9-2.Git
commit()
treeSHA-1commit
commit commit-treetreeSHA-1tree
$echo'firstcommit'|gitcommit-treed8329f
fdf4fc3344e67ab068f836878b6c4951e3b15f3d
cat-filecommit
$gitcat-file-pfdf4fc3
treed8329fc1cc938780ffdd9f94e0d364e0ea74f579
authorScottChacon<[email protected]>1243040974-0700
committerScottChacon<[email protected]>1243040974-0700
firstcommit
commit/Git user.name user.email)
commitcommit
$echo'secondcommit'|gitcommit-tree0155eb-pfdf4fc3
cac0cab538b970a37ea1e769cbbde608743bc96d
$echo'thirdcommit'|gitcommit-tree3c4e9c-pcac0cab
1a410efbd13591db07496601ebc7a059dd55cfe9
commitGit gitlogcommitSHA-1
$gitlog--stat1a410e
commit1a410efbd13591db07496601ebc7a059dd55cfe9
Author:ScottChacon<[email protected]>
Date:FriMay2218:15:242009-0700
thirdcommit
bak/test.txt|1+
1fileschanged,1insertions(+),0deletions(-)
commitcac0cab538b970a37ea1e769cbbde608743bc96d
Author:ScottChacon<[email protected]>
Date:FriMay2218:14:292009-0700
secondcommit
new.txt|1+
test.txt|2+-
2fileschanged,2insertions(+),1deletions(-)
commitfdf4fc3344e67ab068f836878b6c4951e3b15f3d
Author:ScottChacon<[email protected]>
Date:FriMay2218:09:342009-0700
firstcommit
test.txt|1+
1fileschanged,1insertions(+),0deletions(-)
Git gitadd gitcommitGit──blobtreecommitcommittreecommitGit──blobtreetree──
$find.git/objects-typef
.git/objects/01/55eb4229851634a0f03eb265b69f5a2d56f341#tree2
.git/objects/1a/410efbd13591db07496601ebc7a059dd55cfe9#commit3
.git/objects/1f/7a7a472abf3dd9643fd615f6da379c4acb3e3a#test.txtv2
.git/objects/3c/4e9cd789d88d8d89c1073707c3585e41b0e614#tree3
.git/objects/83/baae61804e65cc73a7201a7252750c76066a30#test.txtv1
.git/objects/ca/c0cab538b970a37ea1e769cbbde608743bc96d#commit2
.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4#'testcontent'
.git/objects/d8/329fc1cc938780ffdd9f94e0d364e0ea74f579#tree1
.git/objects/fa/49b077972391ad58037050f2a75f74e3671e92#new.txt
.git/objects/fd/f4fc3344e67ab068f836878b6c4951e3b15f3d#commit1
9-3
Figure9-3.Git
GitRubyblob(“whatisup,doc?”) irbRuby
$irb
>>content="whatisup,doc?"
=>"whatisup,doc?"
Gitblob(nullbyte)
>>header="blob#{content.length}\0"
=>"blob16\000"
GitSHA-1Ruby requireSHA1digest Digest::SHA1.hexdigest()
>>store=header+content
=>"blob16\000whatisup,doc?"
>>require'digest/sha1'
=>true
>>sha1=Digest::SHA1.hexdigest(store)
=>"bd9dbf5aae1a3862dd1526723246b20206e5fc37"
GitzlibRubyzlib Zlib::Deflate.deflate()
>>require'zlib'
=>true
>>zlib_content=Zlib::Deflate.deflate(store)
=>"x\234K\312\311OR04c(\317H,Q\310,V(-\320QH\311O\266\a\000_\034\a\235"
zlib(SHA-138)Ruby FileUtils.mkdir_p()write()
>>path='.git/objects/'+sha1[0,2]+'/'+sha1[2,38]
=>".git/objects/bd/9dbf5aae1a3862dd1526723246b20206e5fc37"
>>require'fileutils'
=>true
>>FileUtils.mkdir_p(File.dirname(path))
=>".git/objects/bd"
>>File.open(path,'w'){|f|f.writezlib_content}
=>32
──blobGit──blobcommittreeblobcommittree
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitReferences gitlog1a410e 1a410eSHA-1SHA-1
Git“”referencesrefs .git/refsSHA-1
$find.git/refs
.git/refs
.git/refs/heads
.git/refs/tags
$find.git/refs-typef
$
$echo"1a410efbd13591db07496601ebc7a059dd55cfe9">.git/refs/heads/master
GitSHA-1
$gitlog--pretty=onelinemaster
1a410efbd13591db07496601ebc7a059dd55cfe9thirdcommit
cac0cab538b970a37ea1e769cbbde608743bc96dsecondcommit
fdf4fc3344e67ab068f836878b6c4951e3b15f3dfirstcommit
Git update-ref
$gitupdate-refrefs/heads/master1a410efbd13591db07496601ebc7a059dd55cfe9
GitHEAD
$gitupdate-refrefs/heads/testcac0ca
$gitlog--pretty=onelinetest
cac0cab538b970a37ea1e769cbbde608743bc96dsecondcommit
fdf4fc3344e67ab068f836878b6c4951e3b15f3dfirstcommit
Git9-4
9-4.Git
gitbranch() Git update-refSHA-1
HEAD
gitbranch() GitSHA-1HEADHEAD————SHA-1
$cat.git/HEAD
ref:refs/heads/master
gitcheckouttestGit
$cat.git/HEAD
ref:refs/heads/test
gitcommitcommitcommitHEADSHA-1
symbolic-refHEAD
$gitsymbolic-refHEAD
refs/heads/master
HEAD
$gitsymbolic-refHEADrefs/heads/test
$cat.git/HEAD
ref:refs/heads/test
refs
$gitsymbolic-refHEADtest
fatal:RefusingtopointHEADoutsideofrefs/
Tags
GitTagcommit——Tagcommittree——commit
Tagannotatedlightweightlightweighttag
$gitupdate-refrefs/tags/v1.0cac0cab538b970a37ea1e769cbbde608743bc96d
lightweighttag——annotatedtagannotatedtagGittagcommitreferenceannotatedtag -aannotatedtag
$gittag-av1.11a410efbd13591db07496601ebc7a059dd55cfe9–m'testtag'
SHA-1
$cat.git/refs/tags/v1.1
9585191f37f7b0fb9444f35a9bf50de191beadc2
cat-fileSHA-1
$gitcat-file-p9585191f37f7b0fb9444f35a9bf50de191beadc2
object1a410efbd13591db07496601ebc7a059dd55cfe9
typecommit
tagv1.1
taggerScottChacon<[email protected]>SatMay2316:48:582009-0700
testtag
commitSHA-1commitGitGitGPGblob
$gitcat-fileblobjunio-gpg-pub
Git.Linuxkernelcommittag——tagtreeinitialtree
Remotes
referenceremotereferenceremoteGitremoteoriginremote master
[email protected]:schacon/simplegit-progit.git
$gitpushoriginmaster
Countingobjects:11,done.
Compressingobjects:100%(5/5),done.
Writingobjects:100%(7/7),716bytes,done.
Total7(delta2),reused4(delta1)
[email protected]:schacon/simplegit-progit.git
a11bef0..ca82a6dmaster->master
refs/remotes/origin/master originremote master
$cat.git/refs/remotes/origin/master
ca82a6dff817ec66f44342007202690a93763949
RemotecheckoutGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
PackfilestestGit11──4blob3tree3committag
$find.git/objects-typef
.git/objects/01/55eb4229851634a0f03eb265b69f5a2d56f341#tree2
.git/objects/1a/410efbd13591db07496601ebc7a059dd55cfe9#commit3
.git/objects/1f/7a7a472abf3dd9643fd615f6da379c4acb3e3a#test.txtv2
.git/objects/3c/4e9cd789d88d8d89c1073707c3585e41b0e614#tree3
.git/objects/83/baae61804e65cc73a7201a7252750c76066a30#test.txtv1
.git/objects/95/85191f37f7b0fb9444f35a9bf50de191beadc2#tag
.git/objects/ca/c0cab538b970a37ea1e769cbbde608743bc96d#commit2
.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4#'testcontent'
.git/objects/d8/329fc1cc938780ffdd9f94e0d364e0ea74f579#tree1
.git/objects/fa/49b077972391ad58037050f2a75f74e3671e92#new.txt
.git/objects/fd/f4fc3344e67ab068f836878b6c4951e3b15f3d#commit1
Gitzlib925GitGritrepo.rb──12K
$curlhttp://github.com/mojombo/grit/raw/master/lib/grit/repo.rb>repo.rb
$gitaddrepo.rb
$gitcommit-m'addedrepo.rb'
[master484a592]addedrepo.rb
3fileschanged,459insertions(+),2deletions(-)
deletemode100644bak/test.txt
createmode100644repo.rb
rewritetest.txt(100%)
treerepo.rbblobSHA-1
$gitcat-file-pmaster^{tree}
100644blobfa49b077972391ad58037050f2a75f74e3671e92new.txt
100644blob9bc1dc421dcd51b4ac296e3e5b6e2a99cf44391erepo.rb
100644blobe3f094f522629ae358806b17daf78246c27c007btest.txt
gitcat-file
$gitcat-file-s9bc1dc421dcd51b4ac296e3e5b6e2a99cf44391e
12898
$echo'#testing'>>repo.rb
$gitcommit-am'modifiedrepoabit'
[masterab1afef]modifiedrepoabit
1fileschanged,1insertions(+),0deletions(-)
committree
$gitcat-file-pmaster^{tree}
100644blobfa49b077972391ad58037050f2a75f74e3671e92new.txt
100644blob05408d195263d853f09dca71d55116663690c27crepo.rb
100644blobe3f094f522629ae358806b17daf78246c27c007btest.txt
blob400Git
$gitcat-file-s05408d195263d853f09dca71d55116663690c27c
12908
12KGit
GitGit(looseobject)Gitpackfile gitgcGitGit
$gitgc
Countingobjects:17,done.
Deltacompressionusing2threads.
Compressingobjects:100%(13/13),done.
Writingobjects:100%(17/17),done.
Total17(delta1),reused10(delta0)
objects
$find.git/objects-typef
.git/objects/71/08f7ecb345ee9d0084193f147cdad4d2998293
.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4
.git/objects/info/packs
.git/objects/pack/pack-7a16e4488ae40c7d2bc56ea2bd43e25212a66c45.idx
.git/objects/pack/pack-7a16e4488ae40c7d2bc56ea2bd43e25212a66c45.pack
commitblob──“whatisup,doc?”“testcontent”blobcommitGit“”packfile
packfilepackfilepackfile gc12Kpackfile6K
GitGitpackfile gitverify-pack
$gitverify-pack-v\
.git/objects/pack/pack-7a16e4488ae40c7d2bc56ea2bd43e25212a66c45.idx
0155eb4229851634a0f03eb265b69f5a2d56f341tree71765400
05408d195263d853f09dca71d55116663690c27cblob129083478874
09f01cea547666f58d6a8d809583841a7c6f0130tree1061075086
1a410efbd13591db07496601ebc7a059dd55cfe9commit225151322
1f7a7a472abf3dd9643fd615f6da379c4acb3e3ablob10195381
3c4e9cd789d88d8d89c1073707c3585e41b0e614tree1011055211
484a59275031909e19aadb7c92262719cfcdf19acommit226153169
83baae61804e65cc73a7201a7252750c76066a30blob10195362
9585191f37f7b0fb9444f35a9bf50de191beadc2tag1361275476
9bc1dc421dcd51b4ac296e3e5b6e2a99cf44391eblob71851931
05408d195263d853f09dca71d55116663690c27c\
ab1afef80fac8e34258ff41fc1b867c702daa24bcommit23215712
cac0cab538b970a37ea1e769cbbde608743bc96dcommit226154473
d8329fc1cc938780ffdd9f94e0d364e0ea74f579tree36465316
e3f094f522629ae358806b17daf78246c27c007bblob14867344352
f8f51d7d8a1760462eca26eebafde32087499533tree106107749
fa49b077972391ad58037050f2a75f74e3671e92blob918856
fdf4fc3344e67ab068f836878b6c4951e3b15f3dcommit177122627
chainlength=1:1object
pack-7a16e4488ae40c7d2bc56ea2bd43e25212a66c45.pack:ok
, 9bc1dblobrepo.rbblob 05408blob 0540812K──
Git gitgc
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
TheRefspec
[email protected]:schacon/simplegit-progit.git
.git/config( origin),URLRefspec:
[remote"origin"]
[email protected]:schacon/simplegit-progit.git
fetch=+refs/heads/*:refs/remotes/origin/*
Refspec + <src>:<dst> <src> <dst> +Git
refspec gitremoteaddGit refs/heads/ refs/remotes/origin/
$gitlogorigin/master
$gitlogremotes/origin/master
$gitlogrefs/remotes/origin/master
Git refs/remotes/origin/master.
Git masterfetch
fetch=+refs/heads/master:refs/remotes/origin/master
gitfetchrefspecrefspec. master origin/mymaster
$gitfetchoriginmaster:refs/remotes/origin/mymaster
refspec.
$gitfetchoriginmaster:refs/remotes/origin/mymaster\
topic:refs/remotes/origin/topic
[email protected]:schacon/simplegit
![rejected]master->origin/mymaster(nonfastforward)
*[newbranch]topic->origin/topic
masterrefspec +
refspec. master experiment
[remote"origin"]
[email protected]:schacon/simplegit-progit.git
fetch=+refs/heads/master:refs/remotes/origin/master
fetch=+refs/heads/experiment:refs/remotes/origin/experiment
fetch=+refs/heads/qa*:refs/remotes/origin/qa*
QA masterQA
[remote"origin"]
[email protected]:schacon/simplegit-progit.git
fetch=+refs/heads/master:refs/remotes/origin/master
fetch=+refs/heads/qa/*:refs/remotes/origin/qa/*
QA
Refspec
QA1 qa/refspec
QA master qa/master
$gitpushoriginmaster:refs/heads/qa/master
Git gitpushorigin push
[remote"origin"]
[email protected]:schacon/simplegit-progit.git
fetch=+refs/heads/*:refs/remotes/origin/*
push=refs/heads/master:refs/heads/qa/master
gitpushorigin master qa/master
refspec
$gitpushorigin:topic
refspec <src>:<dst>, <src> topic
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitHTTP file://,ssh://, git://
GitHTTPGitGETGitsimplegit http-fetch
$gitclonehttp://github.com/schacon/simplegit-progit.git
1 info/refs update-server-infoHTTP post-receive
=>GETinfo/refs
ca82a6dff817ec66f44342007202690a93763949refs/heads/master
SHAHEAD
=>GETHEAD
ref:refs/heads/master
master info/refs ca82a6commit
=>GETobjects/ca/82a6dff817ec66f44342007202690a93763949
(179bytesofbinarydata)
HTTPGETzlibcommmit
$gitcat-file-pca82a6dff817ec66f44342007202690a93763949
treecfda3bf379e4f8dba8717dee55aab78aef7f4daf
parent085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
authorScottChacon<[email protected]>1205815931-0700
committerScottChacon<[email protected]>1240030591-0700
changedtheversionnumber
cfda3bcommittree 085bb3
=>GETobjects/08/5bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
(179bytesofdata)
committree
=>GETobjects/cf/da3bf379e4f8dba8717dee55aab78aef7f4daf
(404-NotFound)
Oops-tree404HTTPGit
=>GETobjects/info/http-alternates
(emptyfile)
objects/info/packs update-server-info
=>GETobjects/info/packs
Ppack-816a9b2334da9953e530f27bcac22082a9f5b835.pack
=>GETobjects/pack/pack-816a9b2334da9953e530f27bcac22082a9f5b835.idx
(4kofbinarydata)
SHA
=>GETobjects/pack/pack-816a9b2334da9953e530f27bcac22082a9f5b835.pack
(13kofbinarydata)
treecommitHEAD masterGit
$gitclonehttp://github.com/schacon/simplegit-progit.git
InitializedemptyGitrepositoryin/private/tmp/simplegit-progit/.git/
gotca82a6dff817ec66f44342007202690a93763949
walkca82a6dff817ec66f44342007202690a93763949
got085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Gettingalternateslistforhttp://github.com/schacon/simplegit-progit.git
Gettingpacklistforhttp://github.com/schacon/simplegit-progit.git
Gettingindexforpack816a9b2334da9953e530f27bcac22082a9f5b835
Gettingpack816a9b2334da9953e530f27bcac22082a9f5b835
whichcontainscfda3bf379e4f8dba8717dee55aab78aef7f4daf
walk085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
walka11bef06a3f659402fe7563abf99ad00de2209e6
HTTPGit
Git send-pack receive-pack send-pack receive-pack
gitpushoriginmaster, originSSHURLGit send-pack
[email protected]"git-receive-pack'schacon/simplegit-progit.git'"
005bca82a6dff817ec66f4437202690a93763949refs/heads/masterreport-statusdelete-refs
003e085bb3bcb608e1e84b2432f8ecbe6306e7e7refs/heads/topic
0000
git-receive-pack masterSHA1 report-status
41005b91191003e62620000
send-packcommit receive-pack masterpack
0085ca82a6dff817ec66f44342007202690a9376394915027957951b64cf874c3557a0f3547bd83b3ff6refs/heads/masterreport-status
00670000000000000000000000000000000000000000cdfdb42577e2506715f8cfeacdbabc092bf63e8drefs/heads/experiment
0000
’0’SHA-1experiment’0’
GitSHASHA1()
000Aunpackok
fetch-pack upload-pack fetch-pack upload-pack
upload-pack receive-packSSHGit9418 fetch-pack
003fgit-upload-packschacon/simplegit-progit.git\0host=myserver.com\0
4Git upload-pack
SSH fetch-pack
[email protected]"git-upload-pack'schacon/simplegit-progit.git'"
fetch-pack upload-pack
0088ca82a6dff817ec66f44342007202690a93763949HEAD\0multi_ackthin-pack\
side-bandside-band-64kofs-deltashallowno-progressinclude-tag
003fca82a6dff817ec66f44342007202690a93763949refs/heads/master
003e085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7refs/heads/topic
0000
receive-packHEAD
fetch-pack“want”SHA“have”SHA“done” upload-pack
0054wantca82a6dff817ec66f44342007202690a93763949ofs-delta
0032have085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
0000
0009done
multi_ack side-band
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGitplumbing──porcelainGitGit
Gitcontent-addressableVCSGitGit
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGitLinuxLinux199120022002BitKeeper
2005BitKeeperLinuxBitKeeperLinuxLinuxLinusTorvalds
*****Linux
2005Git
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Git
GitGit2-1
2-1.
gitstatus
$gitstatus
#Onbranchmaster
nothingtocommit(workingdirectoryclean)
Gitmaster
vimREADME gitstatus
$vimREADME
$gitstatus
#Onbranchmaster
#Untrackedfiles:
#(use"gitadd<file>..."toincludeinwhatwillbecommitted)
#
# README
nothingaddedtocommitbutuntrackedfilespresent(use"gitadd"totrack)
“Untrackedfiles”GitREADME
gitaddREADME
$gitaddREADME
gitstatusREADME
$gitstatus
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
# newfile:README
#
“Changestobecommitted” gitinit gitaddgitadd
benchmarks.rb status
$gitstatus
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
# newfile:README
#
#Changedbutnotupdated:
#(use"gitadd<file>..."toupdatewhatwillbecommitted)
#
# modified:benchmarks.rb
#
benchmarks.rb“Changedbutnotupdated” gitadd
gitaddbenchmarks.rb gitstatus
$gitaddbenchmarks.rb
$gitstatus
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
# newfile:README
# modified:benchmarks.rb
#
benchmarks.rb gitstatus
$vimbenchmarks.rb
$gitstatus
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
# newfile:README
# modified:benchmarks.rb
#
#Changedbutnotupdated:
#(use"gitadd<file>..."toupdatewhatwillbecommitted)
#
# modified:benchmarks.rb
#
benchmarks.rbGitgitadd
$gitaddbenchmarks.rb
$gitstatus
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
# newfile:README
# modified:benchmarks.rb
#
Git.gitignore
$cat.gitignore
*.[oa]
*~
Git.o.aGit ~Emacslogtmppid.gitignore
.gitignore
Gitglob* /* !
globshell * [abc]abc ? [0-9]09
.gitignore
#–Git
*.a#.a
!lib.a#lib.a
/TODO#TODOsubdir/TODO
build/#build/
doc/*.txt#doc/notes.txtdoc/server/arch.txt
gitstatus gitdiff gitdiff gitdiff
READMEbenchmarks.rb status
$gitstatus
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
# newfile:README
#
#Changedbutnotupdated:
#(use"gitadd<file>..."toupdatewhatwillbecommitted)
#
# modified:benchmarks.rb
#
gitdiff
$gitdiff
diff--gita/benchmarks.rbb/benchmarks.rb
index3cb747f..da65585100644
---a/benchmarks.rb
+++b/benchmarks.rb
@@-36,6+36,10@@defmain
@commit.parents[0].parents[0].parents[0]
end
+run_code(x,'commits1')do
+git.commits.size
+end
+
run_code(x,'commits2')do
log=git.commits('master',15)
log.size
gitdiff--cachedGit1.6.1 gitdiff--staged
$gitdiff--cached
diff--gita/READMEb/README
newfilemode100644
index0000000..03902a1
---/dev/null
+++b/README2
@@-0,0+1,5@@
+grit
+byTomPreston-Werner,ChrisWanstrath
+http://github.com/mojombo/grit
+
+GritisaRubylibraryforextractinginformationfromaGitrepository
gitdiff gitdiff
benchmarks.rb gitstatus
$gitaddbenchmarks.rb
$echo'#testline'>>benchmarks.rb
$gitstatus
#Onbranchmaster
#
#Changestobecommitted:
#
# modified:benchmarks.rb
#
#Changedbutnotupdated:
#
# modified:benchmarks.rb
#
gitdiff
$gitdiff
diff--gita/benchmarks.rbb/benchmarks.rb
indexe445e28..86b2f7c100644
---a/benchmarks.rb
+++b/benchmarks.rb
@@-127,3+127,4@@end
main()
##ppGrit::GitRuby.cache_client.stats
+#testline
andgitdiff--cachedtoseewhatyou’vestagedsofar:
$gitdiff--cached
diff--gita/benchmarks.rbb/benchmarks.rb
index3cb747f..e445e28100644
---a/benchmarks.rb
+++b/benchmarks.rb
@@-36,6+36,10@@defmain
@commit.parents[0].parents[0].parents[0]
end
+run_code(x,'commits1')do
+git.commits.size
+end
+
run_code(x,'commits2')do
log=git.commits('master',15)
log.size
gitadd gitstatus gitcommit
$gitcommit
shell$EDITORvimemacs gitconfig--globalcore.editor
Vim
#Pleaseenterthecommitmessageforyourchanges.Linesstarting
#with'#'willbeignored,andanemptymessageabortsthecommit.
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
#newfile:README
#modified:benchmarks.rb
~
~
~
".git/COMMIT_EDITMSG"10L,283C
gitstatus -vGit
-m
$gitcommit-m"Story182:Fixbenchmarksforspeed"
[master]:created463dc4f:"Fixbenchmarksforspeed"
2fileschanged,3insertions(+),0deletions(-)
createmode100644README
masterSHA-1 463dc4f
Git gitcommit -aGit gitadd
$gitstatus
#Onbranchmaster
#
#Changedbutnotupdated:
#
# modified:benchmarks.rb
#
$gitcommit-a-m'addednewbenchmarks'
[master83e38c7]addednewbenchmarks
1fileschanged,5insertions(+),0deletions(-)
gitaddbenchmarks.rb
Git gitrm
gitstatus“Changedbutnotupdated”__
$rmgrit.gemspec
$gitstatus
#Onbranchmaster
#
#Changedbutnotupdated:
#(use"gitadd/rm<file>..."toupdatewhatwillbecommitted)
#
#deleted:grit.gemspec
#
gitrm
$gitrmgrit.gemspec
rm'grit.gemspec'
$gitstatus
#Onbranchmaster
#
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
#deleted:grit.gemspec
#
-fforce
Git .a .gitignore --cached
$gitrm--cachedreadme.txt
glob
$gitrmlog/\*.log
* \Gitshellshell log/
$gitrm\*~
~
VCSGitGitGit
Git mvGit
$gitmvfile_fromfile_to
$gitmvREADME.txtREADME
$gitstatus
#Onbranchmaster
#Yourbranchisaheadof'origin/master'by1commit.
#
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
#renamed:README.txt->README
#
gitmv
$mvREADME.txtREADME
$gitrmREADME.txt
$gitaddREADME
Git gitmv
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Git
gitremoteoriginGit
$gitclonegit://github.com/schacon/ticgit.git
InitializedemptyGitrepositoryin/private/tmp/ticgit/.git/
remote:Countingobjects:595,done.
remote:Compressingobjects:100%(269/269),done.
remote:Total595(delta255),reused589(delta253)
Receivingobjects:100%(595/595),73.31KiB|1KiB/s,done.
Resolvingdeltas:100%(255/255),done.
$cdticgit
$gitremote
origin
-v–verbose
$gitremote-v
origin git://github.com/schacon/ticgit.git
Grit
$cdgrit
$gitremote-v
bakkdoorgit://github.com/bakkdoor/grit.git
cho45git://github.com/cho45/grit.git
defunktgit://github.com/defunkt/grit.git
kokegit://github.com/koke/grit.git
[email protected]:mojombo/grit.git
originSSHURL
gitremoteadd[shortname][url]
$gitremote
origin
$gitremoteaddpbgit://github.com/paulboone/ticgit.git
$gitremote-v
origin git://github.com/schacon/ticgit.git
pb git://github.com/paulboone/ticgit.git
pbPaul gitfetchpb
$gitfetchpb
remote:Countingobjects:58,done.
remote:Compressingobjects:100%(41/41),done.
remote:Total44(delta24),reused1(delta0)
Unpackingobjects:100%(44/44),done.
Fromgit://github.com/paulboone/ticgit
*[newbranch]master->pb/master
*[newbranch]ticgit->pb/ticgit
Paulmaster pb/master
$gitfetch[remote-name]
origin gitfetchoriginfetchfetch
gitpull gitclonemastermastermasterpull
gitpush[remote-name][branch-name]master origin
$gitpushoriginmaster
gitremoteshow[remote-name] origin
$gitremoteshoworigin
*remoteorigin
URL:git://github.com/schacon/ticgit.git
Remotebranchmergedwith'gitpull'whileonbranchmaster
master
Trackedremotebranches
master
ticgit
master gitpull
gitremoteshow
$gitremoteshoworigin
*remoteorigin
URL:[email protected]:defunkt/github.git
Remotebranchmergedwith'gitpull'whileonbranchissues
issues
Remotebranchmergedwith'gitpull'whileonbranchmaster
master
Newremotebranches(nextfetchwillstoreinremotes/origin)
caching
Staletrackingbranches(use'gitremoteprune')
libwalker
walker2
Trackedremotebranches
acl
apiv2
dashboard2
issues
master
postgres
Localbranchpushedwith'gitpush'
master:master
gitpushcachingStaletrackingbranchesissuesmaster
Git gitremoterename pb paul
$gitremoterenamepbpaul
$gitremote
origin
paul
pb/master paul/master
gitremoterm
$gitremotermpaul
$gitremote
origin
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
VCSGitv1.0
gittag
$gittag
v0.1
v1.3
Git2401.4.2
$gittag-l'v1.4.2.*'
v1.4.2.1
v1.4.2.2
v1.4.2.3
v1.4.2.4
GitlightweightannotatedGNUPrivacyGuard(GPG)
-aannotated
$gittag-av1.4-m'myversion1.4'
$gittag
v0.1
v1.3
v1.4
-mGitGit
gitshow
$gitshowv1.4
tagv1.4
Tagger:ScottChacon<[email protected]>
Date:MonFeb914:45:112009-0800
myversion1.4
commit15027957951b64cf874c3557a0f3547bd83b3ff6
Merge:4a447f7...a6b4c97...
Author:ScottChacon<[email protected]>
Date:SunFeb819:02:462009-0800
Mergebranch'experiment'
GPG -a -sSigned
$gittag-sv1.5-m'mysigned1.5tag'
Youneedapassphrasetounlockthesecretkeyfor
user:"ScottChacon<[email protected]>"
1024-bitDSAkey,IDF721C45A,created2009-02-09
gitshowGPG
$gitshowv1.5
tagv1.5
Tagger:ScottChacon<[email protected]>
Date:MonFeb915:22:202009-0800
mysigned1.5tag
-----BEGINPGPSIGNATURE-----
Version:GnuPGv1.4.8(Darwin)
iEYEABECAAYFAkmQurIACgkQON3DxfchxFr5cACeIMN+ZxLKggJQf0QYiQBwgySN
Ki0An2JeAVUCAiJ7Ox6ZEtK+NvZAj82/
=WryJ
-----ENDPGPSIGNATURE-----
commit15027957951b64cf874c3557a0f3547bd83b3ff6
Merge:4a447f7...a6b4c97...
Author:ScottChacon<[email protected]>
Date:SunFeb819:02:462009-0800
Mergebranch'experiment'
-a-s -m
$gittagv1.4-lw
$gittag
v0.1
v1.3
v1.4
v1.4-lw
v1.5
gitshow
$gitshowv1.4-lw
commit15027957951b64cf874c3557a0f3547bd83b3ff6
Merge:4a447f7...a6b4c97...
Author:ScottChacon<[email protected]>
Date:SunFeb819:02:462009-0800
Mergebranch'experiment'
gittag-v[tag-name]verifyGPGkeyring
$gittag-vv1.4.2.1
object883653babd8ee7ea23e6a5c392bb739348b1eb61
typecommit
tagv1.4.2.1
taggerJunioCHamano<[email protected]>1158138501-0700
GIT1.4.2.1
Minorfixessince1.4.2,includinggit-mvandgit-httpwithalternates.
gpg:SignaturemadeWedSep1302:08:252006PDTusingDSAkeyIDF3119B9A
gpg:Goodsignaturefrom"JunioCHamano<[email protected]>"
gpg:aka"[jpegimageofsize1513]"
Primarykeyfingerprint:35652A262040E066C9A74A7DC0C6D9A4F3119B9A
gpg:SignaturemadeWedSep1302:08:252006PDTusingDSAkeyIDF3119B9A
gpg:Can'tchecksignature:publickeynotfound
error:couldnotverifythetag'v1.4.2.1'
$gitlog--pretty=oneline
15027957951b64cf874c3557a0f3547bd83b3ff6Mergebranch'experiment'
a6b4c97498bd301d84096da251c98a07c7723e65beginningwritesupport
0d52aaab4479697da7686c15f77a3d64d9165190onemorething
6d52a271eda8725415634dd79daabbc4d9b6008eMergebranch'experiment'
0b7434d86859cc7b8c3d5e1dddfed66ff742fcbcaddedacommitfunction
4682c3261057305bdd616e23b64b0857d832627baddedatodofile
166ae0c4d3f420721acbb115cc33848dfcc2121astartedwritesupport
9fceb02d0ae598e95dc970b74767f19372d61af8updatedrakefile
964f16d36dfccde844893cac5b347e7b3d44abbccommitthetodo
8a5cbc430f1a9c3d00faaeffd07798508422908aupdatedreadme
“updatedrakefile”v1.2
$gittag-av1.29fceb02
$gittag
v0.1
v1.2
v1.3
v1.4
v1.4-lw
v1.5
$gitshowv1.2
tagv1.2
Tagger:ScottChacon<[email protected]>
Date:MonFeb915:32:162009-0800
version1.2
commit9fceb02d0ae598e95dc970b74767f19372d61af8
Author:MagnusChacon<[email protected]>
Date:SunApr2720:43:352008-0700
updatedrakefile
...
gitpush gitpushorigin[tagname]
$gitpushoriginv1.5
Countingobjects:50,done.
Compressingobjects:100%(38/38),done.
Writingobjects:100%(44/44),4.56KiB,done.
Total44(delta18),reused8(delta1)
[email protected]:schacon/simplegit.git
*[newtag]v1.5->v1.5
--tags
$gitpushorigin--tags
Countingobjects:50,done.
Compressingobjects:100%(38/38),done.
Writingobjects:100%(44/44),4.56KiB,done.
Total44(delta18),reused8(delta1)
[email protected]:schacon/simplegit.git
*[newtag]v0.1->v0.1
*[newtag]v1.2->v1.2
*[newtag]v1.4->v1.4
*[newtag]v1.4-lw->v1.4-lw
*[newtag]v1.5->v1.5
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Git
Git masterdevelopnext——iss53
commit3-18
3-18.
commit3-19
3-19.
proposed puproposedupdates next master
TopicGit
iss53 hotfix——
3-20 masterC1 iss9191C6C4 iss91v2
C10 iss91v2C11 masterC10 dumbidea
3-20.
iss91v2 dumbidea iss91C5C63-21
3-21.dumbideaiss91v2
Git——
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
SSH authorized_keysUbuntuLinux‘git’ .ssh
$sudoaddusergit
$sugit
$cd
$mkdir.ssh
SSH authorized_keyse-mail
$cat/tmp/id_rsa.john.pub
ssh-rsaAAAAB3NzaC1yc2EAAAADAQABAAABAQCB007n/ww+ouN4gSLKssMxXnBOvf9LGt4L
ojG6rs6hPB09j9R/T17/x4lhJA0F3FR1rP6kYBRsWj2aThGw6HXLm9/5zytK6Ztg3RPKK+4k
Yjh6541NYsnEAZuXz0jTTyAUfrtU3Z5E003C4oxOj6H0rfIF1kKI9MAQLMdpGW1GYEIgS9Ez
Sdfd8AcCIicTDWbqLAcU4UpkaX8KyGlLwsNuuGztobF8m72ALC/nLF6JLtPofwFBlgc+myiv
O7TCUSBdLQlgMVOFq1I2uPWQOkOWQAHukEOmfjy2jctxSDBQ220ymjaNsHT4kgtZg2AYYgPq
dAv8JggJICUvax2T9va5gsg-keypair
authorized_keys
$cat/tmp/id_rsa.john.pub>>~/.ssh/authorized_keys
$cat/tmp/id_rsa.josie.pub>>~/.ssh/authorized_keys
$cat/tmp/id_rsa.jessica.pub>>~/.ssh/authorized_keys
--bare gitinit
$cd/opt/git
$mkdirproject.git
$cdproject.git
$git--bareinit
JoinJosieJessicashell gitserver git
gitserver
#John
$cdmyproject
$gitinit
$gitadd.
$gitcommit-m'initialcommit'
$gitremoteaddorigingit@gitserver:/opt/git/project.git
$gitpushoriginmaster
$gitclonegit@gitserver:/opt/git/project.git
$vimREADME
$gitcommit-am'fixfortheREADMEfile'
$gitpushoriginmaster
Git
Git git-shell gitGit gitshellshellshellcsh /etc/passwd
$sudovim/etc/passwd
git:x:1000:1000::/home/git:/bin/sh
bin/sh /usr/bin/git-shell whichgit-shell
git:x:1000:1000::/home/git:/usr/bin/git-shell
gitSSHGitshell
$sshgit@gitserver
fatal:WhatdoyouthinkIam?Ashell?shell)
Connectiontogitserverclosed.gitserver
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
CVCSGitGitGit
5-1
5-1.
GitSubversionCVCS
Gitfast-forward
Gitblessedrepositorydeveloperpublicintegrationmanager5-2
1. blessedrepository2.2. developerpublic4.3. integrationmanger4. blessedrepository
5-2.
GitHubfork
Linuxlieutenantdictator5-3
1. dectatormaster2. lieutenantmaster3. dictatormastermaster4. dictatormasterblessedrepository
5-3.
Git
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
format-patch
ruby_clientGit sc/ruby_client
$gitbranchsc/ruby_clientmaster
checkout-b
$gitcheckout-bsc/ruby_clientmaster
gitapply gitam
apply
gitdiffUnix diff gitapply /tmp/patch-ruby-client.patch
$gitapply/tmp/patch-ruby-client.patch
patch-p1 gitdiff patchpatch gitapply patch
gitapply--check
$gitapply--check0001-seeing-if-this-helps-the-gem.patch
error:patchfailed:ticgit.gemspec:1
error:ticgit.gemspec:patchdoesnotapply
shell
am
Git format-patch format-patch diff gitapply
format-patch gitam gitammboxFrom
From330090432754092d704da8e76ca5c05c198e71a8MonSep1700:00:002001
From:JessicaSmith<[email protected]>
Date:Sun,6Apr200810:17:23-0700
Subject:[PATCH1/2]addlimittologfunction
Limitlogfunctionalitytothefirst20
format-patchmbox gitsend-email gitammbox
format-patchRequestTicket gitam
$gitam0001-limit-log-function.patch
Applying:addlimittologfunction
From Date Subjectmbox
$gitlog--pretty=fuller-1
commit6c5e70b984a60b3cecd395edd5b48a7575bf58e0
Author:JessicaSmith<[email protected]>
AuthorDate:SunApr610:17:232008-0700
Commit:ScottChacon<[email protected]>
CommitDate:ThuApr909:19:062009-0700
addlimittologfunction
Limitlogfunctionalitytothefirst20
Commit Author
gitam
$gitam0001-seeing-if-this-helps-the-gem.patch
Applying:seeingifthishelpsthegem
error:patchfailed:ticgit.gemspec:1
error:ticgit.gemspec:patchdoesnotapply
Patchfailedat0001.
Whenyouhaveresolvedthisproblemrun"gitam--resolved".
Ifyouwouldprefertoskipthispatch,insteadrun"gitam--skip".
Torestoretheoriginalbranchandstoppatchingrun"gitam--abort".
Git gitam--resolved
$(fixthefile)
$gitaddticgit.gemspec
$gitam--resolved
Applying:seeingifthishelpsthegem
Git -3
$gitam-30001-seeing-if-this-helps-the-gem.patch
Applying:seeingifthishelpsthegem
error:patchfailed:ticgit.gemspec:1
error:ticgit.gemspec:patchdoesnotapply
Usingindexinfotoreconstructabasetree...
Fallingbacktopatchingbaseand3-waymerge...
Nochanges--Patchalreadyapplied.
-3
mbox am -i
$gitam-3-imbox
CommitBodyis:
--------------------------
seeingifthishelpsthegem
--------------------------
Apply?[y]es/[n]o/[e]dit/[v]iewpatch/[a]cceptall
Git
Jessica ruby-client
$gitremoteaddjessicagit://github.com/jessica/myproject.git
$gitfetchjessica
$gitcheckout-brubyclientjessica/ruby-client
-3
gitpull
$gitpullgit://github.com/onetimeguy/project.git
Fromgit://github.com/onetimeguy/project
*branchHEAD->FETCH_HEAD
Mergemadebyrecursive.
contrib --not master
$gitlogcontrib--notmaster
commit5b6235bd297351589efc4d73316f0a68d484f118
Author:ScottChacon<[email protected]>
Date:FriOct2409:53:592008-0700
seeingifthishelpsthegem
commit7482e0d16d04bea79d0dba8988cc78df655f16a0
Author:ScottChacon<[email protected]>
Date:MonOct2219:38:362008-0700
updatedthegemspectohopefullyworkbetter
gitlog -p
$gitdiffmaster
master diff master
master master
master
$gitmerge-basecontribmaster
36c7dba2c95e6bbb78dfa822519ecfec6e1ca649
$gitdiff36c7db
Git ... diff ...
$gitdiffmaster...contrib
master ruby_client php_client5-19php_client5-20
5-19.
5-20.
master develop5-21 ruby_client develop5-22 C8
master5-23 C8
5-21.
5-22.
5-23.
develop
Git master next pupuproposedupdates maint
maintenance5-24
5-24.
pu master next master master next pu5-25
5-25.
masterGit maintGit
cherry-pick
develop master
commits5-26
Figure5-26.cherry-pick
e43a6
$gitcherry-picke43a6fd3e94888d76779ad79fb568ed180e5fcdf
Finishedonecherry-pick.
[master]:createda0a41a9:"Morefriendlymessagewhenlockingtheindexfails."
3fileschanged,17insertions(+),3deletions(-)
e43a6SHA-15-27.
Figure5-27.cherry-pick
commit
$gittag-sv1.5-m'mysigned1.5tag'
Youneedapassphrasetounlockthesecretkeyfor
user:"ScottChacon<[email protected]>"
1024-bitDSAkey,IDF721C45A,created2009-02-09
PGPpublickeyGitkeyblobGit
$gpg--list-keys
/Users/schacon/.gnupg/pubring.gpg
---------------------------------
pub1024D/F721C45A2009-02-09[expires:2010-02-09]
uidScottChacon<[email protected]>
sub2048g/45D022822009-02-09[expires:2010-02-09]
key githash-objectblobGitblobSHA-1
$gpg-a--exportF721C45A|githash-object-w--stdin
659ef797d181633c87ec71ac3f9ba29fe5775b92
GitkeySHA-1key
$gittag-amaintainer-pgp-pub659ef797d181633c87ec71ac3f9ba29fe5775b92
gitpush--tags maintainer-pgp-pubkey
$gitshowmaintainer-pgp-pub|gpg--import
key gitshow<tag>
Git’v123’ gitdescribeGitSHA-1ofthecommityou’redescribing
$gitdescribemaster
v1.6.2-rc1-20-g8c5b85c
Git git--version describe
gitdescribe -a-s gitdescribe checkoutshowSHA-1SHA-1LinuxSHA-1810gitdescribe
Git gitarchive
$gitarchivemaster--prefix='project/'|gzip>`gitdescribemaster`.tar.gz
$ls*.tar.gz
v1.6.2-rc1-20-g8c5b85c.tar.gz
zip gitarchive--format=zip
$gitarchivemaster--prefix='project/'--format=zip>`gitdescribemaster`.zip
tar.gzzipe-mail
gitshortlogchangelogbug;v1.0.1
$gitshortlog--no-mergesmaster--notv1.0.1
ChrisWanstrath(8):
AddsupportforannotatedtagstoGrit::Tag
Addpacked-refsannotatedtagsupport.
AddGrit::Commit#to_patch
UpdateversionandHistory.txt
Removestray`puts`
Makels_treeignorenils
TomPreston-Werner(4):
fixdatesinhistory
dynamicversionmethod
Versionbumpto1.0.2
Regeneratedgemspecforversion1.0.2
v1.0.1e-mail
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Git
gitadd-i--interactiveGitshell
$gitadd-i
stagedunstagedpath
1:unchanged+0/-1TODO
2:unchanged+1/-1index.html
3:unchanged+5/-1lib/simplegit.rb
***Commands***
1:status2:update3:revert4:adduntracked
5:patch6:diff7:quit8:help
Whatnow>
——gitstatus
Whatnow>2u
Whatnow>2
stagedunstagedpath
1:unchanged+0/-1TODO
2:unchanged+1/-1index.html
3:unchanged+5/-1lib/simplegit.rb
Update>>
TODOindex.html
Update>>1,2
stagedunstagedpath
*1:unchanged+0/-1TODO
*2:unchanged+1/-1index.html
3:unchanged+5/-1lib/simplegit.rb
Update>>
* update>>Git
Update>>
updated2paths
***Commands***
1:status2:update3:revert4:adduntracked
5:patch6:diff7:quit8:help
Whatnow>1
stagedunstagedpath
1:+0/-1nothingTODO
2:+1/-1nothingindex.html
3:unchanged+5/-1lib/simplegit.rb
TODOindex.htmlsimplegit.rbTODO 3rrevert
***Commands***
1:status2:update3:revert4:adduntracked
5:patch6:diff7:quit8:help
Whatnow>3
stagedunstagedpath
1:+0/-1nothingTODO
2:+1/-1nothingindex.html
3:unchanged+5/-1lib/simplegit.rb
Revert>>1
stagedunstagedpath
*1:+0/-1nothingTODO
2:+1/-1nothingindex.html
3:unchanged+5/-1lib/simplegit.rb
Revert>>[enter]
revertedonepath
GitTODO
***Commands***
1:status2:update3:revert4:adduntracked
5:patch6:diff7:quit8:help
Whatnow>1
stagedunstagedpath
1:unchanged+0/-1TODO
2:+1/-1nothingindex.html
3:unchanged+5/-1lib/simplegit.rb
6ddiff gitdiff--cached
***Commands***
1:status2:update3:revert4:adduntracked
5:patch6:diff7:quit8:help
Whatnow>6
stagedunstagedpath
1:+1/-1nothingindex.html
Reviewdiff>>1
diff--gita/index.htmlb/index.html
index4d07108..4335f49100644
---a/index.html
+++b/index.html
@@-16,7+16,7@@DateFinder
<pid="out">...</p>
-<divid="footer">contact:[email protected]</div>
+<divid="footer">contact:[email protected]</div>
<scripttype="text/javascript">
Gitsimplegit.rbGit 5ppatchGit
diff--gita/lib/simplegit.rbb/lib/simplegit.rb
indexdd5ecc4..57399e0100644
---a/lib/simplegit.rb
+++b/lib/simplegit.rb
@@-22,7+22,7@@classSimpleGit
end
deflog(treeish='master')
-command("gitlog-n25#{treeish}")
+command("gitlog-n30#{treeish}")
end
defblame(path)
Stagethishunk[y,n,a,d,/,j,J,g,e,?]?
?
Stagethishunk[y,n,a,d,/,j,J,g,e,?]??
y-stagethishunk
n-donotstagethishunk
a-stagethisandalltheremaininghunksinthefile
d-donotstagethishunknoranyoftheremaininghunksinthefile
g-selectahunktogoto
/-searchforahunkmatchingthegivenregex
j-leavethishunkundecided,seenextundecidedhunk
J-leavethishunkundecided,seenexthunk
k-leavethishunkundecided,seepreviousundecidedhunk
K-leavethishunkundecided,seeprevioushunk
s-splitthecurrenthunkintosmallerhunks
e-manuallyeditthecurrenthunk
?-printhelp
yn
Whatnow>1
stagedunstagedpath
1:unchanged+0/-1TODO
2:+1/-1nothingindex.html
3:+1/-1+4/-0lib/simplegit.rb
simplegit.rb gitcommit
——gitadd-pgitadd--patch
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Stashinggitstash
“‘”“————
gitstatus
$gitstatus
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
#modified:index.html
#
#Changedbutnotupdated:
#(use"gitadd<file>..."toupdatewhatwillbecommitted)
#
#modified:lib/simplegit.rb
#
gitstash
$gitstash
Savedworkingdirectoryandindexstate\
"WIPonmaster:049d078addedtheindexfile"
HEADisnowat049d078addedtheindexfile
(Torestorethemtype"gitstashapply")
$gitstatus
#Onbranchmaster
nothingtocommit(workingdirectoryclean)
gitstashlist
$gitstashlist
stash@{0}:WIPonmaster:049d078addedtheindexfile
stash@{1}:WIPonmaster:c264051...Revert"addedfile_size"
stash@{2}:WIPonmaster:21d80a5...addednumbertolog
stash gitstashapply gitstashapplystash@{2}
$gitstashapply
#Onbranchmaster
#Changedbutnotupdated:
#(use"gitadd<file>..."toupdatewhatwillbecommitted)
#
#modified:index.html
#modified:lib/simplegit.rb
#
Git——Git
gitstashapply --index
$gitstashapply--index
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
#modified:index.html
#
#Changedbutnotupdated:
#(use"gitadd<file>..."toupdatewhatwillbecommitted)
#
#modified:lib/simplegit.rb
#
apply—— gitstashdrop
$gitstashlist
stash@{0}:WIPonmaster:049d078addedtheindexfile
stash@{1}:WIPonmaster:c264051...Revert"addedfile_size"
stash@{2}:WIPonmaster:21d80a5...addednumbertolog
$gitstashdropstash@{0}
Droppedstash@{0}(364e91f3f268f0900bc3ee613f9f733e82aaed43)
gitstashpop
gitstashbranch
$gitstashbranchtestchanges
Switchedtoanewbranch"testchanges"
#Onbranchtestchanges
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
#modified:index.html
#
#Changedbutnotupdated:
#(use"gitadd<file>..."toupdatewhatwillbecommitted)
#
#modified:lib/simplegit.rb
#
Droppedrefs/stash@{0}(f0dfc4d5dc332d1cee34a634182e168c4efc3359)
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
AtomAtomCPANinstallRubygem
GitGitGit
RackRubyweb gitsubmoduleadd
$gitsubmoduleaddgit://github.com/chneukirchen/rack.gitrack
InitializedemptyGitrepositoryin/opt/subtest/rack/.git/
remote:Countingobjects:3181,done.
remote:Compressingobjects:100%(1534/1534),done.
remote:Total3181(delta1951),reused2623(delta1603)
Receivingobjects:100%(3181/3181),675.42KiB|422KiB/s,done.
Resolvingdeltas:100%(1951/1951),done.
rackRack gitstatus
$gitstatus
#Onbranchmaster
#Changestobecommitted:
#(use"gitresetHEAD<file>..."tounstage)
#
#newfile:.gitmodules
#newfile:rack
#
.gitmodulesURL
$cat.gitmodules
[submodule"rack"]
path=rack
url=git://github.com/chneukirchen/rack.git
.gitignore
gitstatusrack gitdiff
$gitdiff--cachedrack
diff--gita/rackb/rack
newfilemode160000
index0000000..08d709f
---/dev/null
+++b/rack
@@-0,0+1@@
+Subprojectcommit08d709f78b8c5b0fbeb7821e37fa53e69afcf433
rackGitGitHEAD
master
$gitcommit-m'firstcommitwithsubmodulerack'
[master0550271]firstcommitwithsubmodulerack
2fileschanged,4insertions(+),0deletions(-)
createmode100644.gitmodules
createmode160000rack
rack160000Git
rackGit
$gitlog-1
commit0550271328a0038865aad6331e620cd7238601bb
Author:ScottChacon<[email protected]>
Date:ThuApr909:03:562009-0700
firstcommitwithsubmodulerack
$cdrack/
$gitlog-1
commit08d709f78b8c5b0fbeb7821e37fa53e69afcf433
Author:ChristianNeukirchen<[email protected]>
Date:WedMar2514:49:042009+0100
Documentversionchange
$gitclonegit://github.com/schacon/myproject.git
InitializedemptyGitrepositoryin/opt/myproject/.git/
remote:Countingobjects:6,done.
remote:Compressingobjects:100%(4/4),done.
remote:Total6(delta0),reused0(delta0)
Receivingobjects:100%(6/6),done.
$cdmyproject
$ls-l
total8
-rw-r--r--1schaconadmin3Apr909:11README
drwxr-xr-x2schaconadmin68Apr909:11rack
$lsrack/
$
rack gitsubmoduleinit gitsubmoduleupdate
$gitsubmoduleinit
Submodule'rack'(git://github.com/chneukirchen/rack.git)registeredforpath'rack'
$gitsubmoduleupdate
InitializedemptyGitrepositoryin/opt/myproject/rack/.git/
remote:Countingobjects:3181,done.
remote:Compressingobjects:100%(1534/1534),done.
remote:Total3181(delta1951),reused2623(delta1603)
Receivingobjects:100%(3181/3181),675.42KiB|173KiB/s,done.
Resolvingdeltas:100%(1951/1951),done.
Submodulepath'rack':checkedout'08d709f78b8c5b0fbeb7821e37fa53e69afcf433'
rackrack
$gitmergeorigin/master
Updating0550271..85a3eee
Fastforward
rack|2+-
1fileschanged,1insertions(+),1deletions(-)
[master*]$gitstatus
#Onbranchmaster
#Changedbutnotupdated:
#(use"gitadd<file>..."toupdatewhatwillbecommitted)
#(use"gitcheckout--<file>..."todiscardchangesinworkingdirectory)
#
#modified:rack
#
$gitdiff
diff--gita/rackb/rack
index6c5e70b..08d709f160000
---a/rack
+++b/rack
@@-1+1@@
-Subprojectcommit6c5e70b984a60b3cecd395edd5b48a7575bf58e0
+Subprojectcommit08d709f78b8c5b0fbeb7821e37fa53e69afcf433
gitsubmoduleupdate
$gitsubmoduleupdate
remote:Countingobjects:5,done.
remote:Compressingobjects:100%(3/3),done.
remote:Total3(delta1),reused2(delta0)
Unpackingobjects:100%(3/3),done.
[email protected]:schacon/rack
08d709f..6c5e70bmaster->origin/master
Submodulepath'rack':checkedout'6c5e70b984a60b3cecd395edd5b48a7575bf58e0'
gitsubmoduleupdate
$gitsubmoduleupdate
fatal:referenceisn’tatree:6c5e70b984a60b3cecd395edd5b48a7575bf58e0
Unabletocheckout'6c5e70b984a60b3cecd395edd5ba7575bf58e0'insubmodulepath'rack'
$gitlog-1rack
commit85a3eee996800fcfa91e2119372dd4172bf76678
Author:ScottChacon<[email protected]>
Date:ThuApr909:19:142009-0700
addedasubmodulereferenceIwillnevermakepublic.hahahahaha!
CVSSubversion
GitGitGit
gitsubmoduleupdate——HEAD submoduleupdate
updateGit
gitcheckout-b
$gitcheckout-brack
Switchedtoanewbranch"rack"
[email protected]:schacon/rack.gitrack
InitializedemptyGitrepositoryin/opt/myproj/rack/.git/
...
Receivingobjects:100%(3184/3184),677.42KiB|34KiB/s,done.
Resolvingdeltas:100%(1952/1952),done.
$gitcommit-am'addedracksubmodule'
[rackcc49a69]addedracksubmodule
2fileschanged,4insertions(+),0deletions(-)
createmode100644.gitmodules
createmode160000rack
$gitcheckoutmaster
Switchedtobranch"master"
$gitstatus
#Onbranchmaster
#Untrackedfiles:
#(use"gitadd<file>..."toincludeinwhatwillbecommitted)
#
#rack/
——
Gitrack submoduleaddGit
$rm-Rfrack/
[email protected]:schacon/rack.gitrack
'rack'alreadyexistsintheindex
rack
$gitrm-rrack
[email protected]:schacon/rack.gitrack
InitializedemptyGitrepositoryin/opt/testsub/rack/.git/
remote:Countingobjects:3184,done.
remote:Compressingobjects:100%(1465/1465),done.
remote:Total3184(delta1952),reused2770(delta1675)
Receivingobjects:100%(3184/3184),677.42KiB|88KiB/s,done.
Resolvingdeltas:100%(1952/1952),done.
——
$gitcheckoutmaster
error:Untrackedworkingtreefile'rack/AUTHORS'wouldbeoverwrittenbymerge.
rack
$mvrack/tmp/
$gitcheckoutmaster
Switchedtobranch"master"
$ls
README rack
rack gitsubmoduleupdate /tmp/rack
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
GitGitGit .gitattributes .git/info/attributes
GitGit
GitGit—Git
MacXcode .pbxprojIDEJSONjavascriptASCII—2
Git pbxproj .gitattributes
*.pbxproj-crlf-diff
GitCRLFgitshowgitdiffGit1.6 -crlf-diff
*.pbxprojbinary
Git1.6GitGitdiff
WordWordGit gitdiff
$gitdiff
diff--gita/chapter1.docb/chapter1.doc
index88839c4..4afcb7c100644
Binaryfilesa/chapter1.docandb/chapter1.docdiffer
WordGit .gitattributes
*.docdiff=word
”doc”Git”word””word”Git stringsWord
$gitconfigdiff.word.textconvstrings
.docGit”word”Word
Git gitdiff
$gitdiff
diff--gita/chapter1.docb/chapter1.doc
indexc1c8a0a..b93c9e4100644
---a/chapter1.doc
+++b/chapter1.doc
@@-8,7+8,8@@regoingtocoverVersionControlSystems(VCS)andGitbasics
regoingtocoverhowtogetitandsetitupforthefirsttimeifyoudon
talreadyhaveitonyoursystem.
InChapterTwowewillgooverbasicGitusage-howtouseGitforthe80%
-sgoingon,modifystuffandcontributechanges.Ifthebookspontaneously
+sgoingon,modifystuffandcontributechanges.Ifthebookspontaneously
+Let'sseeifthisworks.
Git”Let’sseeifthisworks”Word stringsMacLinux
JPEGEXIF— exiftool
$echo'*.pngdiff=exif'>>.gitattributes
$gitconfigdiff.exif.textconvexiftool
gitdiff
diff--gita/image.pngb/image.png
index88839c4..4afcb7c100644
---a/image.png
+++b/image.png
@@-1,12+1,12@@
ExifToolVersionNumber:7.74
-FileSize:70kB
-FileModificationDate/Time:2009:04:2107:02:45-07:00
+FileSize:94kB
+FileModificationDate/Time:2009:04:2107:02:43-07:00
FileType:PNG
MIMEType:image/png
-ImageWidth:1058
-ImageHeight:889
+ImageWidth:1056
+ImageHeight:827
BitDepth:8
ColorType:RGBwithAlpha
SVNCVSGitGitGit2
blobSHA-1 $Id$GitblobSHA-1SHAblob
$echo'*.txtident'>>.gitattributes
$echo'$Id$'>test.txt
GitblobSHA
$rmtext.txt
$gitcheckout--text.txt
$cattest.txt
$Id:42812b7653c7b88933f8a9d6cad0ca16714b9bb3$
SHACVSSubversion
2”clean””smudge” .gitattributes”smudge”7-2”clean”7-3
7-2.“smudge”
7-3.“clean”
indentC .gitattributes”indent” *.c
*.cfilter=indent
Git”indent””smudge””clean”
$gitconfig--globalfilter.indent.cleanindent
$gitconfig--globalfilter.indent.smudgecat
*.c indent cat catC indent
RCS$Date$Ruby
#!/usr/bin/envruby
data=STDIN.read
last_date=`gitlog--pretty=format:"%ad"-1`
putsdata.gsub('$Date$','$Date:'+last_date.to_s+'$')
gitlog $Date$ $Date$— expand_dateGit dater
$gitconfigfilter.dater.smudgeexpand_date
$gitconfigfilter.dater.clean'perl-pe"s/\\\$Date[^\\\$]*\\\$/\\\$Date\\\$/"'
Perl$Date$ $Date$ $Date$Git
$echo'#$Date$'>date_test.txt
$echo'date*.txtfilter=dater'>>.gitattributes
$gitadddate_test.txt.gitattributes
$gitcommit-m"TestingdateexpansioninGit"
$rmdate_test.txt
$gitcheckoutdate_test.txt
$catdate_test.txt
#$Date:TueApr2107:26:522009-0700$
.gitattributes dater
Git
export-ignore
Git export-ignore
test/Git
test/export-ignore
gitarchive
export-subst
2 --pretty=format$Format:$ LAST_COMMIT gitarchive
$echo'Lastcommitdate:$Format:%cd$'>LAST_COMMIT
$echo"LAST_COMMITexport-subst">>.gitattributes
$gitaddLAST_COMMIT.gitattributes
$gitcommit-am'addingLAST_COMMITfileforarchives'
gitarchive
$catLAST_COMMIT
Lastcommitdate:$Format:TueApr2108:38:482009-0700$
GitGit
database.xml2
database.xmlmerge=ours
database.xml
$gitmergetopic
Auto-mergingdatabase.xml
Mergemadebyrecursive.
database.xml
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
Chapter8
GitGitVCS,VersionControlSystemSubversion gitsvn
GitGitSubversionPerforce
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.
ProGit professionalversioncontrol
Home Book Blog About SupportUs
Thisisanin-progresstranslation.Tohelptranslatethebook,pleaseforkthebookatGitHubandpushyourcontributions.
──
Git“autogc”(looseobject,packfile)packfileGit(garbagecollect)packfilepackfilepackfilecommit()
autogc
$gitgc--auto
7,00050packfileGitgc gc.auto gc.autopacklimit
gc(references)
$find.git/refs-typef
.git/refs/heads/experiment
.git/refs/heads/master
.git/refs/tags/v1.0
.git/refs/tags/v1.1
gitgc,refsGit .git/packed-refs
$cat.git/packed-refs
#pack-refswith:peeled
cac0cab538b970a37ea1e769cbbde608743bc96drefs/heads/experiment
ab1afef80fac8e34258ff41fc1b867c702daa24brefs/heads/master
cac0cab538b970a37ea1e769cbbde608743bc96drefs/tags/v1.0
9585191f37f7b0fb9444f35a9bf50de191beadc2refs/tags/v1.1
^1a410efbd13591db07496601ebc7a059dd55cfe9
Git refs/headsSHAGit refs packed-refs
refs
^annotatedcommit
Gitcommithard-resetcommitcommit
testhard-resetcommitcommit
$gitlog--pretty=oneline
ab1afef80fac8e34258ff41fc1b867c702daa24bmodifiedrepoabit
484a59275031909e19aadb7c92262719cfcdf19aaddedrepo.rb
1a410efbd13591db07496601ebc7a059dd55cfe9thirdcommit
cac0cab538b970a37ea1e769cbbde608743bc96dsecondcommit
fdf4fc3344e67ab068f836878b6c4951e3b15f3dfirstcommit
mastercommit
$gitreset--hard1a410efbd13591db07496601ebc7a059dd55cfe9
HEADisnowat1a410efthirdcommit
$gitlog--pretty=oneline
1a410efbd13591db07496601ebc7a059dd55cfe9thirdcommit
cac0cab538b970a37ea1e769cbbde608743bc96dsecondcommit
fdf4fc3344e67ab068f836878b6c4951e3b15f3dfirstcommit
commit──commitcommitSHAcommitSHA──SHA
gitreflog()GitHEADreflog gitupdate-ref
References”SHAref
$gitreflog
1a410efHEAD@{0}:1a410efbd13591db07496601ebc7a059dd55cfe9:updatingHEAD
ab1afefHEAD@{1}:ab1afef80fac8e34258ff41fc1b867c702daa24b:updatingHEAD
commit gitlog-greflog
$gitlog-g
commit1a410efbd13591db07496601ebc7a059dd55cfe9
Reflog:HEAD@{0}(ScottChacon<[email protected]>)
Reflogmessage:updatingHEAD
Author:ScottChacon<[email protected]>
Date:FriMay2218:22:372009-0700
thirdcommit
commitab1afef80fac8e34258ff41fc1b867c702daa24b
Reflog:HEAD@{1}(ScottChacon<[email protected]>)
Reflogmessage:updatingHEAD
Author:ScottChacon<[email protected]>
Date:FriMay2218:15:242009-0700
modifiedrepoabit
commitcommitcommit(ab1afef) recover-branch
$gitbranchrecover-branchab1afef
$gitlog--pretty=onelinerecover-branch
ab1afef80fac8e34258ff41fc1b867c702daa24bmodifiedrepoabit
484a59275031909e19aadb7c92262719cfcdf19aaddedrepo.rb
1a410efbd13591db07496601ebc7a059dd55cfe9thirdcommit
cac0cab538b970a37ea1e769cbbde608743bc96dsecondcommit
fdf4fc3344e67ab068f836878b6c4951e3b15f3dfirstcommit
master recover-branchcommit
commitreflog── recover-branchreflogcommit
$gitbranch–Drecover-branch
$rm-Rf.git/logs/
reflog .git/logs/reflogcommit gitfsck
$gitfsck--full
danglingblobd670460b4b4aece5915caf5c68d12f560a9fe3e4
danglingcommitab1afef80fac8e34258ff41fc1b867c702daa24b
danglingtreeaea790b9a58f6cf6f2804eeac9f0abbe9631e4c9
danglingblob7108f7ecb345ee9d0084193f147cdad4d2998293
danglingcommitcommitSHA
Git gitcloneGit
SubversionPerforceGit()()
treecommit──()commit
test
$curlhttp://kernel.org/pub/software/scm/git/git-1.6.3.1.tar.bz2>git.tbz2
$gitaddgit.tbz2
$gitcommit-am'addedgittarball'
[master6df7640]addedgittarball
1fileschanged,0insertions(+),0deletions(-)
createmode100644git.tbz2
tar
$gitrmgit.tbz2
rm'git.tbz2'
$gitcommit-m'oops-removedlargetarball'
[masterda3f30d]oops-removedlargetarball
1fileschanged,0insertions(+),0deletions(-)
deletemode100644git.tbz2
gc
$gitgc
Countingobjects:21,done.
Deltacompressionusing2threads.
Compressingobjects:100%(16/16),done.
Writingobjects:100%(21/21),done.
Total21(delta3),reused15(delta1)
count-objects
$gitcount-objects-v
count:4
size:16
in-pack:21
packs:1
size-pack:2016
prune-packable:0
garbage:0
size-packpackfiles2MB2K──2MB
() gitgcpackfile gitverify-pack
$gitverify-pack-v.git/objects/pack/pack-3f8c0...bb.idx|sort-k3-n|tail-3
e3f094f522629ae358806b17daf78246c27c007bblob14867344667
05408d195263d853f09dca71d55116663690c27cblob1290834781189
7a9eb2fba2b1811321254ac360970fc169ba2330blob205671620568725401
2MB7 rev-list rev-list --objectscommitSHAblobSHAblob
$gitrev-list--objects--all|grep7a9eb2fb
7a9eb2fba2b1811321254ac360970fc169ba2330git.tbz2
treecommit
$gitlog--pretty=oneline--git.tbz2
da3f30d019005479c99eb4c3406225613985a1dboops-removedlargetarball
6df764092f3e7c8f5f94cbe08ee5cf42e92a0289addedgittarball
6df76commitGit6 filter-branch
$gitfilter-branch--index-filter\
'gitrm--cached--ignore-unmatchgit.tbz2'--6df7640^..
Rewrite6df764092f3e7c8f5f94cbe08ee5cf42e92a0289(1/2)rm'git.tbz2'
Rewriteda3f30d019005479c99eb4c3406225613985a1db(2/2)
Ref'refs/heads/master'wasrewritten
--index-filter6 --tree-filter rmfile gitrm--cached
──Gitfilterfilter-branch 6df7640commit
reflog filter-branchGit .git/refs/originalrefsrepackrepackcommits
$rm-Rf.git/refs/original
$rm-Rf.git/logs/
$gitgc
Countingobjects:19,done.
Deltacompressionusing2threads.
Compressingobjects:100%(14/14),done.
Writingobjects:100%(19/19),done.
Total19(delta3),reused16(delta1)
$gitcount-objects-v
count:8
size:2040
in-pack:19
packs:1
size-pack:7
prune-packable:0
garbage:0
repack7K2MBsize gitprune--expire
prev|next
BooktranslatedintoGerman,Chinese,JapaneseandDutch.PartialtranslationsavailableinArabic,Czech,Spanish,French,Indonesian,Italian,
Macedonian,Polish,ThaiandRussian.AllcontentunderCreativeCommonsAttribution-NonCommercial-ShareAlike3.0license.
ThemeandcodebyMichaelBleigh.HostedbyGitHubandpoweredbyJekyll.