Transcription

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesAn Introduction to (Easy) GitElijah NewrenElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesTrivial changes for most developersOperations will be fasterExtra robustnessThe basics are the same.unless you make policy decisions otherwiseTrivial changes for most developersYou may often hear that Git requires drastically differentworkflows.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesTrivial changes for most developersOperations will be fasterExtra robustnessThe basics are the same.unless you make policy decisions otherwiseTrivial changes for most developersYou may often hear that Git requires drastically differentworkflows.While Git allows drastically different workflows, and somepeople promote them.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesTrivial changes for most developersOperations will be fasterExtra robustnessThe basics are the same.unless you make policy decisions otherwiseTrivial changes for most developersYou may often hear that Git requires drastically differentworkflows.While Git allows drastically different workflows, and somepeople promote them.The change from Subversion to (Easy) Git can be easier thanthe transition from CVS to Subversion.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesTrivial changes for most developersOperations will be fasterExtra robustnessThe basics are the same.unless you make policy decisions otherwiseCaching more dataProject checkouts containCVS: data metadataSVN: data extra copy metadata(faster diffs against last revision)GIT: data all history metadata(most operations faster, new operations possible)Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesTrivial changes for most developersOperations will be fasterExtra robustnessThe basics are the same.unless you make policy decisions otherwiseCaching more dataProject checkouts containCVS: data metadataSVN: data extra copy metadata(faster diffs against last revision)GIT: data all history metadata(most operations faster, new operations possible)Client disk data usage, relative to size of most recent revision:CVS: 1 (typical is about 1.2)SVN: 2 (typical is about 2.2)GIT: 1 (typical is in the range 1.9-2.5)Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesTrivial changes for most developersOperations will be fasterExtra robustnessThe basics are the same.unless you make policy decisions otherwiseImproved data integrityGit has very strong safeguards against corruption, whetheraccidental (e.g. disk/memory/cpu failure) or malicious. It is notpossible to change published revisions without being noticed.Git achieves this through tracking cryptographic checksums offiles, subtrees, trees, and commits.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesTrivial changes for most developersOperations will be fasterExtra robustnessThe basics are the same.unless you make policy decisions otherwiseThe basics are essentially the samesvn checkout URLsvn statussvn updatesvn diffsvn add FILEsvn commitCore commandseg clone URLeg statuseg updateeg diffeg add FILEeg commiteg pushOther common commandssvn blame FILEeg blame FILEsvn cat FILEeg cat FILEsvn help [COMMAND]eg help [COMMAND]svn infoeg infosvn mv OLDNAME NEWNAMEeg mv OLDNAME NEWNAMEsvn resolved PATH.eg resolved PATH.svn revert PATH.eg revert PATH.svn rm FILE.eg rm FILE.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesTrivial changes for most developersOperations will be fasterExtra robustnessThe basics are the same.unless you make policy decisions otherwise.unless you make policy decisions otherwiseGit has a lot of extra capabilities that you can use withoutchanging the basic model.If you want to adopt a linux-like development model, you can.But most projects don’t adopt such practices, at least not at first(and often not ever.)Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesTrivial changes for most developersOperations will be fasterExtra robustnessThe basics are the same.unless you make policy decisions otherwise.unless you make policy decisions otherwiseGit has a lot of extra capabilities that you can use withoutchanging the basic model.If you want to adopt a linux-like development model, you can.But most projects don’t adopt such practices, at least not at first(and often not ever.)Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesTrivial changes for most developersOperations will be fasterExtra robustnessThe basics are the same.unless you make policy decisions otherwise.unless you make policy decisions otherwiseGit has a lot of extra capabilities that you can use withoutchanging the basic model.If you want to adopt a linux-like development model, you can.But most projects don’t adopt such practices, at least not at first(and often not ever.)Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesCloneCommitStatusDiffLogBasic CommandsElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesCloneCommitStatusDiffLogCloneThe clone command obtains a copy of a project for you (thusmaking it analagous to svn checkout.) eg clone /home/newren/floss/gtk -gitInitialized empty Git repository in /home/newren/devel/gtk -git/.gitChecking out files: 100% (2691/2691), done.Valid URLs are project directory names accessed by variousprotocols; examples:eg clone [email protected]:/home/coworker/projecteg clone git://git.samba.org/samba.giteg clone http://git.gitorious.org/eg/mainline.git egeg clone /PATH/TO/PROJECT NEWNAMEElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesCloneCommitStatusDiffLogCommitThe commit command records changes locally. eg commit -m "Random change, just for the fun of it"Created commit 2ebb10a: Random change, just for the fun of it1 files changed, 1 insertions( ), 0 deletions(-)To push this commit to the repository you cloned from, run eg pushYou can queue multiple commits before pushing, which allowscheckpointing code that is not ready for everyone else in amore fine-grained fashion.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesCloneCommitStatusDiffLogStatusThe status commands shows which branch is active, and listsfiles according to their status (modified, unmerged (“hasconflicts”), deleted, unknown, etc.) eg status(On branch master)Changed but not updated rc/tools/metacity-message.cUnknown tElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesCloneCommitStatusDiffLogDiffThe diff command shows changes in patch format. eg diffdiff --git a/src/utils.py b/src/utils.pyindex 2ad4d53.c76b540 100644--- a/src/utils.py b/src/[email protected]@ -454,4 454,5 @@ class Task(object):return value def add(self, item, count):self.container.insert(item, count)if count:self.container.insert(item, count)Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesCloneCommitStatusDiffLogLogThe log command shows the history of changes. eg logcommit 23dbb9a7643186c1402709e535622595e9b857a1 (master)Author: Elijah Newren [email protected] Date:Fri Oct 3 20:35:26 2008 -0600Mark the current version of eg as .93; it’s time to releaseIf you look at .93 upside down, it kind of looks like E-G.:-)commit 3f767870a7c70ba518217dac4e5ed6738176c783 (master 1)Author: Elijah Newren [email protected] Date:Thu Oct 2 21:56:20 2008 -0600Fix weird bug when sh ! bash: caret needs to be quoted on Sun machinesThe commandgit branch sed -e s/ .//was failing which caused some nasty messages and warnings on Sunmachines. I don’t know why sh doesn’t like this command, but quotingthe substitution command avoids the problem.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesOnly use what you needIt has been said that few users make use of more than 20% ofthe features in a word processor.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesOnly use what you needIt has been said that few users make use of more than 20% ofthe features in a word processor.I probably use less than 1%.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesOnly use what you needIt has been said that few users make use of more than 20% ofthe features in a word processor.I probably use less than 1%.But it is nice to know the other features are there.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesOnly use what you needGit has a lot of features.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesOnly use what you needGit has a lot of features.You don’t need to use or even understand 1% of them.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesOnly use what you needGit has a lot of features.You don’t need to use or even understand 1% of them.But here’s a brief introduction to what’s possible.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesStashing changes awayStaging changesBisecting history to find a bad commitUsing branches for different projectsJust stick it under version controlTime saversElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesStashing changes awayStaging changesBisecting history to find a bad commitUsing branches for different projectsJust stick it under version controlStashingThe stash command saves any uncommitted changes in yourproject, and returns you to a clean slate. The stash commandcan also be used to reapply previously stashed away changes. eg stash Do a bunch of other stuff, even including making commits eg stash applyYou can have multiple stashes and name them, if you like. eg stash save Stuff I was doing before customer called eg stash save Crazy idea eg stash apply Stuff I was doing before customer calledElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesStashing changes awayStaging changesBisecting history to find a bad commitUsing branches for different projectsJust stick it under version controlStagingIn git, you can explicitly mark a subset of your changes asbeing ready for commit. You can also make additional changes,and then just commit the changes that are ready. echo hi there eg stage there echo "hi again" there eg commit --staged -m "New single-line file called there"Created commit b7e2002: New single-line file called there1 files changed, 1 insertions( ), 0 deletions(-)create mode 100644 there eg status(On branch testing)Changed but not updated ("unstaged"):modified:thereElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesStashing changes awayStaging changesBisecting history to find a bad commitUsing branches for different projectsJust stick it under version controlBisectingGit provides a bisect command for finding the commit thatintroduced some bug through a binary search of history. eg bisect start BAD REVISION GOOD REVISION Repeat until done: Compile, link, test, see if given revision is good or bad eg bisect bad eg bisect goodYou can automate that looping step with a script that compiles,links, tests, and returns whether the given revision is good: eg bisect run NAME OF SCRIPTElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesStashing changes awayStaging changesBisecting history to find a bad commitUsing branches for different projectsJust stick it under version controlBranchingGit makes both branching and merging easy, fast, and robust. eg branch newbranch eg switch newbranch Work on newbranch eg switch original-branch Work on original-branch Then merging another branch into the current one is as simpleas eg merge newbranchIf you want to merge changes back the other way: eg switch newbranch eg merge original-branchElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesStashing changes awayStaging changesBisecting history to find a bad commitUsing branches for different projectsJust stick it under version controlSetting up repositoriesGit makes it really easy to just stick data under version control. eg init eg add . eg commit Make more changes eg commit.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesPulling changes directly from another developerGrabbing multiple branches at oncePatch reviewWorking with firewalled developersCollaborationElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesPulling changes directly from another developerGrabbing multiple branches at oncePatch reviewWorking with firewalled developersPulling changesOne can pull updates or changes from the original repositoryyou cloned from eg pullBut it’s just as easy to pull changes directly from anotherrepository eg pull --branch some-branch URL-OR-PATH-TO-PROJECTIf you pull from the same person often, you can add a nicknamefor their repository eg remote add jim URL-OR-PATH-TO-PROJECT eg pull --branch some-branch jimElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesPulling changes directly from another developerGrabbing multiple branches at oncePatch reviewWorking with firewalled developersFetching multiple branches simultaneouslyYou can pull the branches in bob’s repository, and stick them inbranches in your repository with the name bob/ branch eg fetch bobThis assumes you’ve already set up bob as a nickname for hisrepository, by running: eg remote add bob URLElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesPulling changes directly from another developerGrabbing multiple branches at oncePatch reviewWorking with firewalled developersPatch reviewGit makes it easy to submit patches for review via email. eg format-patch --numbered master.working-branch eg send-email --compose --to [email protected] is also easy to apply patches received in email (even someemails not formatted by git), if you can figure out how to get therelevant emails saved off into a separate mbox file: eg am mbox-file(’am’ stands for ’apply [a series of patches from] mail’.)Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesPulling changes directly from another developerGrabbing multiple branches at oncePatch reviewWorking with firewalled developersCreating and Using BundlesCreate a bundle in the filebundle.file that contains thewhole repository eg bundle create bundle.fileAfter a while, create a file tosend them updates mv bundle.file old-repo eg bundle create-update \bundle.file old-repoThe collaborator, aftersomehow receiving this file, can run eg clone \/path/to/bundle.file projectAfter sending them the newrepo.bundle file, they stick the file in the same place and run eg pullThey can also send you bundles, and you treat the filename asa repository URL to pull from.Elijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesThere are more useful commands.and more.and some that will blow your mindWe’ve just scratched the surfaceElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesThere are more useful commands.and more.and some that will blow your mindRevertYou can revert the uncommitted changes to a set of files ordirectories eg revert foo.txt bar.c eg revert srcYou can also revert to a prior revision eg revert --since REVISION srcor revert the changes made in a prior revision eg revert --in REVISION srcElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesThere are more useful commands.and more.and some that will blow your mindHigh level change statisticsYou can get high-level statistics about the number of changesper file. eg diff --statOr the percentage of line changes by directory eg diff --dirstator the type of changes to each file (equivalent to cvs updateoutput) eg diff --name-statusor just the names of the files that have changed eg diff --name-onlyElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesThere are more useful commands.and more.and some that will blow your mindLogs with additional informationYou can combine patches (diffs) with logs eg log -pOr, high level patch statistics t--name-status--name-onlyElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesThere are more useful commands.and more.and some that will blow your mindShorter change logsYou can get just the summary of each change message eg log --pretty onelineOr the one-line summaries grouped by author eg shortlogYou can also easily specify a range for either of these eg shortlog gnome-2-24.masterElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesThere are more useful commands.and more.and some that will blow your mindSearching for changesYou can look for string or regex matches in currently checkedout files eg grep PATTERNor in files of a previous revision eg grep PATTERN REVISIONor in the files under a specific directory of a previous revision eg grep PATTERN REVISION -- DIRECTORYElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional FeaturesThere are more useful commands.and more.and some that will blow your mindSearching for changesYou can search for when some text was introduced eg log -S’FIXME’Or when some text matching a regular expression wasintroduced eg log -S’\bHACK #[0-9] :’--pickaxe-regexElijah NewrenAn Introduction to (Easy) Git

Changes, or lack thereofBasic CommandsTime saversCollaborationAdditional F