Git
-
Upload
it-booze -
Category
Technology
-
view
2.156 -
download
0
Transcript of Git
GIT
BySerhiy Yakovyn
Agenda
• Describe how GIT commands corresponds to SubVersioN ones.
• Provide some commonly used workflows.• Explain how to use GIT when your team works
with SVN.• Give a quick overview of GIT internals
GIT to SVN mapping
Create the new repo:svnadmin create reposvn import file://repo
git initgit add .git commit
GIT to SVN mapping
To revert:svn revert pathGit checkout path
GIT to SVN mapping
To commit:svn commit
git commit -a
GIT to SVN mapping
Branching:svn copy http://example.com/svn/trunk http://example.com/svn/branches/branch svn switch http://example.com/svn/branches/branch
git branch branch git checkout branch
GIT to SVN mapping
List:svn list http://example.com/svn/branches/git branch
GIT to SVN mapping
Moving between revisions:svn update -r revsvn update
git checkout rev git checkout prevbranch
GIT to SVN mapping
(assuming the branch was created in revision 20 and you are inside a working copy of trunk) svn merge -r 20:HEAD http://example.com/svn/branches/branch
git merge branch
GIT to SVN mapping
Pick commit from another branch:svn merge -c rev urlgit cherry-pick rev
GIT to SVN mapping
Cloning remote repo:svn checkout url
git clone url
GIT to SVN mapping
Remote branch:svn switch urlgit checkout --track -b branch origin/branch
GIT to SVN mapping
Remote update:svn updategit pull
GIT to SVN mapping
Remote commit:svn commitgit push
Some commonly used workflows
1. Write new features in feature branches.2. Integrate on the master branch.3. Deploy from the release branch.
Some commonly used workflows
1. Write new features in feature branches.# create a new feature branch in the remote repo named feature_branch git push origin master:refs/heads/feature_branch
# make sure we've got everything updated from the remote repo git fetch origin
# create a local branch named feature_branch that tracks # the remote feature_branch git branch --track feature_branch origin/feature_branch
# check out the new branch git checkout feature_branch
Some commonly used workflows
2. Integrate on master branch.git merge master
git checkout master git merge feature_branch
# this has to be in competition for one of the least intuitive # commands ever, but it removes the remote branch git push origin :refs/heads/feature_branch
# remove the local branch git branch -d feature_branch
Some commonly used workflows3. Deploy from the release branch.# checkout the deploy branch git checkout deploy
# pull the deploy branch, just to be sure everything's up to date git pull origin deploy
# merge the master branch into the deploy branch git merge master
# tag the release that we're about to make git tag -a -m "My comments about this release" [tag_name]
# push it all up to the remote repository git push --tags origin deploy
# switch back to the master branch, # since we never do any work on the deploy branch git checkout master
Some commonly used workflows
1. Pull to update your local master2. Check out a feature branch3. Do work in your feature branch, committing early and often4. Rebase frequently to incorporate upstream changes5. Interactive rebase (squash) your commits6. Merge your changes with master7. Push your changes to the upstream
Some commonly used workflows
1. Pull to update your local mastergit checkout mastergit pull origin master
Some commonly used workflows
2. Check out a branchgit checkout -b <branch>
Some commonly used workflows
3. Do work in your feature branch, committing early and oftenHacking…git commitHacking…git commitHacking…git commit
Some commonly used workflows
4. Rebase frequently to incorporate upstream changesgit fetch origin master git rebase origin/masterOr (longer way):git checkout master git pull git checkout <branch> git rebase master
Some commonly used workflows
5. Interactive rebase (squash) your commitsgit rebase -i origin/master
Some commonly used workflows
6. Merge your changes with mastergit checkout mastergit pull git merge <branch>
Some commonly used workflows
7. Push your changes to the upstreamgit push origin master
GIT SVN
How to use GIT when your team works with SVN?1. Creating working copy? – no! working repo.git svn init …Some magic git svn fetchOr (if you are lucky! – I’ve never been):git svn clone …
GIT SVN
2. Hacking. Just usual GITgit checkout –b <branch>hacking…git commithacking…
GIT SVN
3. Updating from SVNgit svn rebaseorgit svn fetchgit svn rebase –l
GIT SVN
4. Preparing your workgit rebase –i remote/<branch>
GIT SVN
5. Committing back to SVNgit svn dcommit
GIT SVN
6. Branching:git svn branch
GIT internals
.git contentHEAD – the checked out branchconfig – configuration options description – description (used by GitWeb)hooks/ index - staginginfo/ objects/ - contentrefs/ - pointers to commit objects in branches
GIT internals
Git is a content-addressable filesystem.This means that at the core of Git is a simple key-value data store. You can insert any kind of content into it, and it will give you back a key that you can use to retrieve the content again at any time. git hash-object – stores the file in GIT
GIT internals
git cat-file - provides content or type and size information for repository objects
BLOB – basic object type. Every file is stored in it
GIT internals
Tree object
GIT internals
Tree objectgit update-indexgit write-treegit read-tree
GIT internals
Commit Objectsgit commit-tree
GIT internals
Git Referencesgit update-ref
Questions?
Useful links
http://progit.org/book/Git Workflow – GitHubGit SVN Workflowhttp://maymay.net/blog/2009/02/24/how-to-use-git-svn-as-the-only-subversion-client-youll-need/and many-many-many others…