Download presentation
Presentation is loading. Please wait.
1
Version Control Systems
Introduction to GIT Version Control Systems
2
Version Control Version control (a.k.a. revision control) is a system that records changes to a file or set of files over time so that you can retrieve specific versions later and manage a collection of files for use by a group project Version Control can be: Local Centralized Distributed
3
Local A Local VCS uses a simple database to keep all the changes to files under revision control.
4
Centralized Version Control
Centralized Version Control Systems have a single server that contains all the versioned files, and a number of clients that check out files from that central place.
5
Distributed Version Control
In a distributed VCS, clients don’t just check out the latest snapshot of the files: they fully mirror the repository.
6
Distributed Version Control
GIT is a distributed version control system A master authoritative server is only used if desired by a project Every checked out copy is a repository Version control can be used even when detached from server Backup of a repository is trivial Other distributed systems include Mercurial BitKeeper Darcs Bazaar
7
Git Advantages Resilience Speed Space Simplicity
No one repository has more data than any other Speed Very fast operations compared to most VCS Space Compression can be done across repository not just per file Minimizes local size as well as push/pull data transfers Simplicity Object model is very simple Large user base with robust tools Open source, free
8
Some GIT Disadvantages
Definite learning curve, especially for those used to centralized systems must pay attention to follow recommended procedures when several people are working on a project Documentation mostly through man pages and web wikis Windows support is not as well developed as for Linux/Unix
9
Git Workflow
10
Git Architecture Workspace (working directory) Index Object Database
A regular directory that contains a git repository (.git subdirectory) Index Stores information about current working directory and changes made to it Object Database Blobs (files) Stored in .git/objects Each indexed by unique hash All files are stored as blobs Commits One object is stored for every commit Contains hash of parent, name of author, time of commit, and hash of the current tree Tags
11
Some Commands Getting a Repository Commits Getting information
git init git clone Commits git add git commit Getting information git help git status git diff git log git show
12
Our First Git Repository
mkdir gitRepo1 cd gitRepo1 git init Creates an initial repository in the .git subdirectory echo "Hello World" >hello.txt git status shows which files have been modified in working directory and/or index since the last commit
13
Our First Git Repository
(in directory gitRepo1) git add . adds all changed files in the current working directory to the index of the current repository makes the index reflect the working tree used to stage changes for a commit (decide which files should be committed prior to a commit) git commit -m 'Check in #1' Stores the current contents of the index in a new commit along with a log message describing the changes A commit operation is what actually updates the repository
14
Working With Git echo "I love Git" >>hello.txt git diff
Shows what changes we have made compares working tree with index by default git status Shows list of modified files git add hello.txt No changes shown now, as working tree and index are the same git diff HEAD Compares working tree with latest commit (HEAD) git commit -m 'Check in #2'
15
Viewing History git log git show <OBJECT> git reflog
Shows a log of commits, with most recent first Note the hash code, which identifies each commit git show <OBJECT> OBJECT can be a full or shortened hash code git reflog to show all updates that have occurred to the current branch
16
Undoing What is Done git checkout <branch>
Used to checkout a specific version/branch of the tree git revert <commit> Makes a new commit that reverses the effect of an earlier commit Example: git revert HEAD Does not delete the commit object, just applies a patch Reverts can themselves be reverted! git reset Moves the working tree back to a certain specified version Use the --force if you really want to ignore working changes Ordinary git commands do not delete commit objects It is very hard to shoot yourself in the foot!
17
Git and Tagging Tags are just human readable shortcuts for hashes
A tag can be created to refer to any commit git tag –a <tag-name> [<commit>] Creates a tag to refer to the given commit (HEAD by default) git tag –l List all tags git show-ref --tags Show all tags with their commit hashes
18
Branching Multiple branches allow you to work on a new part of a system without disrupting the stable version of the system Git branching is lightweight Most of the code does not need to be copied Tools for helping merge branches and changes easily You are ALWAYS working on a branch By default, you are working on a branch named “master” Branches can be local or remote Key commands git branch Lists all local branches available in the current repository The current branch is highlighted with *
19
Using Branches git checkout -b newbranch git branch
A branch named newbranch is created and checked out The new branch will start with the same content as the current branch Make sure you have committed changes in the current branch before switching to a new branch git branch Check which branch is currently checked out We can now make changes in one branch and then propagate changes using git merge git cherry-pick
20
Branching Example Simple branching: start a new branch (mywork) to develop an experimental feature or work on fixing a bug o--o--o <-- master \ a--b--c <-- mywork
21
Branching Example More work done on master branch
o--o--O--o--o--o <-- master \ a--b--c <-- mywork
22
Merging Example Could merge changes from master into the current branch (mywork) git merge master o--o--O--o--o--o <-- master \ a--b--c--m<-- mywork
23
Merging Example o--o--O--o--o--m <-- master \ a--b--c <-- mywork
When an experimental branch has been adequately tested, we can merge it into the master branch git checkout master git merge mywork o--o--O--o--o--m <-- master \ a--b--c <-- mywork
24
Cleaning Up git fsck git gc
Checks object database to make sure all is sane Can show information about dangling objects git gc Cleans up repository and compress files When used with --prune, cleans out dangling blobs Can speed up larger repositories, but not often necessary for small projects
25
Using a Remote Repository
Replicate a remote repository git clone Get changes with git fetch git pull (fetches and merges) Propagate changes with git push Protocols Local filesystem SSH Rsync HTTP Git protocol
26
Cloning our Repository
git clone first-git-repo Now have a full git repository to work with Changes are pushed back with git push Pushing changes WILL NOT change working copy on the repository being worked on Branches can be based off of remote branches git branch --track new-branch remote/branch Remote configuration information stored in .git/config Can have multiple remote backends!
27
Git for Software Versioning
Create convention to define default server Developers clone from central server Lots of tools for transmitting patches between developers Being used for Linux (obviously) Ruby On Rails Check out for a variety of hosted projects
28
Git for Backups Example: A directory needs regular backups
Could use Linux rsync, but unwieldy in size Create Git repository for appropriate directory regular local commits regular push to backup location Can store/retrieve simple revision history
29
Git for Configuration Management
Example: Apache configurations Multiple environments (dev/test/production) Each environment is a separate branch Tags are defined for each release version Minor differences between environments IP Address Log levels Want to effectively move changes across environments
30
Further Resources http://git-scm.com/ Git project home page
user-manual.html
31
Key Git Files/Directories
~/.gitconfig .git In top level directory of repository Contains all objects, commits, configuration, for project .git/config has project specific configurations .gitignore Stored in directory for ignoring
32
Some Git Coolness NetBeans provides interface to use projects with Git
gitk Linux GUI to review changes bash/zsh completion git instaweb Used for starting HTTP process for browing project
33
Git and Other VCS Integrations with
Subversion CVS Darcs Many others Example of integration with Subversion Use git-svn to fetch and commit push Note initial fetch may take a long time as each commit is downloaded individually! Use git commands for everything Branches integrated with tags and branches
34
Git and Patch files git diff HEAD^^ git diff HEAD~10..HEAD~2
Show what has changed in last two commits git diff HEAD~10..HEAD~2 Show what changed between 10 commits ago and two commits ago git format-patch HEAD^^..HEAD Will create individual patch files per commit git apply to apply patches git am to apply patches from an mbox Can also compare Between specific objects To branches/tags
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.