Sie sind auf Seite 1von 36

Change Management

Week 4

Version Control Tools

What is version control?


Version management allows you to control and monitor changes to files
What changes were made? Revert to pervious versions When were changes made What code was present in release 2.7?

Earliest tools were around 1972 (SCCS) Older tools RCS, CVS, Microsoft Source Safe, PVCS Version Manager, etc Current tools Subversion, Mercurial, Git, Bazaar

Introduction To GIT

Terminologies
Backporting
Action of taking a certain software modification(patch) and applying it to an older version of the software than it was initially created for.

Repository
A data structure usually stored on a server that contains:
A set of files and directories. Historical record of changes in the repository. A set of commit objects. A set of references to commit objects, called heads.

Working Copy
A local copy of files from a repository, at a specific time or revision.

Terminologies contd
Commit
An action of writing or merging the changes made in the working copy back to the repository.

Check-out
The act of creating a local working copy from the repository. A user may specify a specific revision or obtain the latest.

Centralized Version Control


Traditional version control system
Server with database Clients have a working version

Examples
CVS(Concurrent Versioning System) SVN(Subversion) Visual Source Safe

Challenges
Multi-developer conflicts Client/server communication

Distributed Version Control


Authoritative server by convention only Every working checkout is a repository Get version control even when detached Backups are trivial Other distributed systems include
Mercurial BitKeeper Darcs Bazaar

Git Advantages
Resilience
No one repository has more data than any other

Speed
Very fast operations compared to other VCS (Im looking at you CVS and Subversion)

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 userbase with robust tools

Some GIT Disadvantages


Gradual learning curve, especially for those used to centralized systems
Can sometimes seem overwhelming to learn

Documentation mostly through man pages

Windows support can be an issue


Can use through Cygwin Also have the msysgit project Integrate Git to Visual Studio or Eclipse

Git Architecture
Index
Stores information about current working directory and changes made to it.

Object Database
Blobs (files)
Stored in .git/objects. Indexed by unique hash. All files are stored as blobs.

Trees (directories) Commits


One object for every commit. Contains hash of parent, name of author, time of commit, and hash of the current tree.

Tags
Reference to another object and can hold additional meta-data related to another object.

Git Architecture contd


^ means the first parent

Git Architecture contd


Head
Head will be used to refer exclusively to a single commit object, the most recent commit in the branch. A head(lowercase) refers to any one of the named heads (master, stable, dust) in the repository.

HEAD
Refers exclusively to the currently active head. This distinction is used frequently in Git documentation.

Detached HEAD
A git repository is a tree-of-commits, with each commit pointing to its ancestor(s). If a commit hash which isn't pointed to by a tag or a branch is checked out, you get a detached head. How to resolve this issue?
Create a new branch to retain commits you create. $ git checkout -b new_branch_name

Git Architecture contd


Master
The default branch created in the repository.

Branch
Branch and Head are nearly synonymous. Every Branch is represented by one Head, and every Head represents one Branch. Sometimes, Branch will be used to refer to a head and the entire history of ancestor commits preceding that head.

Head
Head will be used to refer exclusively to a single commit object, the most recent commit in the branch. A head(lowercase) refers to any one of the named heads (master, stable, dust) in the repository.

HEAD
Refers exclusively to the currently active head. This distinction is used frequently in Git documentation.

Some Commands
Getting a Repository
git init git clone

Getting information
git help git status git diff git log git show

Commits
git add git commit

Key Git Files/Directories


~/.gitconfig .git
In top level of repository Contains all objects, commits, configuration, for project .git/config has project specific configurations

.gitignore
Stored in directory for ignoring

Our First Git Repository


$ mkdir gitroot $ cd gitroot $ git init
Creates the basic artifacts in the .git directory

$ echo Hello World > hello.txt $ git add .


Adds content to the index Index reflects the working version Must be run prior to a commit

$ git commit -am Check in number one

Working With Git


$ echo I love Git >> hello.txt $ git diff
Shows changes we have made

$ git status
Shows list of modified files

$ git add hello.txt $ git diff


No changes shown as diff compares to the index

$ git diff HEAD


Now can see the changes in working version

$ git status $ git commit -m Second commit

Git and Tagging


Tags are just human readable shortcuts for hashes Branches can be made from any commit git tag <tag-name>

Branching
Git branching is lightweight
No massive copying a la CVS/Subversion Tools for helping merge branches and changes easily

You are ALWAYS on a branch Branches can be local or remote Key commands
git branch git merge git cherry-pick
Allows you to choose specific commits to apply You can edit the commits while cherry picking

Using Branches
git checkout -b branch git checkout -b devel/branch git branch
Lists all local branches available

We can now make changes in one branch and propagate change using
git merge git cherry-pick

Viewing What Has Changed


git log
Note the hash code for each commit.

git show <OBJECT>


Can use full or shortened hash

git reflog to see all changes that have occurred

Comparing the changes in Coreutils-8.0


$ $ $ $ $ $ git git git git git git log diff hash-code1 hash-code2 > patch diff master branch_name > patch diff HEAD^ HEAD > patch format-patch master format-patch n

n: newest n commits

Undoing What is Done


git checkout
Used to checkout a specific version/branch of the tree

git reset
Moves the tree back to a certain specified version Use the --force to ignore working changes

git revert
Reverts a commit Does not delete the commit object, just applies a patch Reverts can themselves be reverted!

Git never deletes a commit object


It is very hard to shoot yourself in the foot!

Rebasing Example
Simple branching o--o--o <-- origin \ a--b--c <-- mywork

Rebasing Example
Work done on origin branch o--o--O--o--o--o <-- origin \ a--b--c <-- mywork

Rebasing Example
Could merge changes into branch git merge origin o--o--O--o--o--o <-- origin \ \ a--b--c--m<-- mywork

Rebasing Example
Rebasing moves branch point git rebase origin o--o--O--o--o--o <-- origin \ a`--b`--c`

Cleaning Up
git clean
Cleaning up untracked files.

git fsck
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 really speed up larger repositories

Lab: Managing a backported change

Install Git on Ubuntu/SEASnet


Ubuntu
$ sudo apt-get install git

SEASnet
Git is in /usr/local/cs/bin. $ bash $ vim(emacs) .bashrc Add the following lines PATH=$PATH:/usr/local/cs/bin export PATH Save and quit. $ source .bashrc

Your default shell should be bash in order to use .bashrc. Whenever you login run $ source .bashrc.

Getting Started
$ mkdir gitroot $ cd gitroot $ git clone git://git.savannah.gnu.org/diffutils.git
Getting a Copy of the Git Repository

$ git add . $ cd diffutils $ git log


Copy and paste to git-log.txt.

$ git tag
Copy and paste to git-tags.txt.

$ git show > quote-patch.txt


Generate a patch for that commit.

$ git checkout v3.0


Check out diffutils 3.0.

Apply patch
$ patch < quote-patch.txt
Only the files that are in the current working directory(~/gitroot/diffutils/) are patched. If the patch command outputs error message, hit Enter key twice. You have to change the directory to apply all the patch content.
$ cd man, $ cd src, $ cd doc, $ cd tests, and so forth.

$ cd man $ patch < ../quote-patch.txt (since the patch file is in the upper directory) Apply the patch for all the files.

$ git status $ git revert


Revert changes except for the .c files.

Homework: Verifying and publishing a backported change

Instructions
Check out version 3.0 of diffutils from your repository, into a new branch named quote.
Use git branch.

Install your change into this new branch, by running the patch command with your patch quote-3.0-patch.txt as input.
Use patch command.

Create an appropriate entry in the ChangeLog file for your patch, by adapting the change log from the original patch.
Edit the Changelog file.

Instructions contd
Commit your changes to the new branch.
Use git commit.

Use the command git format-patch to generate a file formatted-patch.txt. This patch should work without having to fix things by hand afterwards.
Use git format-patch.

Verify that this patch works, by checking out version 3.0 again into a new temporary branch tmp, applying the patch with the command git am, and building the resulting system, checking that it works with make check.

Das könnte Ihnen auch gefallen