Git flow for working on svn branch

July 25, 2011 by · Comments Off on Git flow for working on svn branch
Filed under: git 

The Problem: you want to play on git code branches on svn server. Here’s the simple flow.

1. Specify the layout when running git svn clone:

Specify the trunk, branch and tags by -T,-b,-t, such as: -T dev -b branches -t tags

2. To fetch all updates of all svn server branches:

git svn fetch

When you run git svn fetch, all branches will be updated, and new branches on the remote will be added. git svn fetch fetches the updates with out modifying the local working files (while git svn rebase would).

3. To show all branches include server branches:

git branch -r

4. To switch to work on a server branch: server-branch-v2.8

git checkout -b local-v2.8 server-branch-v2.8 then working on the local-2.8 branch, and commit, dcommit, your changes would be dcommitted to the server branch.

Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

git svn workflow and some tips

May 29, 2011 by · Comments Off on git svn workflow and some tips
Filed under: git 

Git svn simple tutorial

1. get a copy of your project from svn server by git svn clone:

git svn clone –no-metadata /path/to/svn/project

(alt: git-svn init https://svn.kde.org/home/kde/trunk/kdesupport/strigi)

some example:

git svn clone -T http://192.168.1.5/svn/search/dev  search-git

git clone a repository with customized project layout( dev as trunk, release as tags) and only the versions after 9999 (note: 9999 must be an existant version in svn):

git svn clone -r9999:HEAD http://192.168.1.5/svn/search/ search-git  -T dev -b branches -t release
2.  check project status by git status

cd project,  git status

3. Download new revisions from SVN:

git svn fetch

4.Update your working dir:

git svn rebase

and working on your projects, add new code, fix bug…
Then try to see commit to local repository by : git commit -a -m “commit message” –dry-runif all changes are desired to be commited, run commit by : git commit -a -m “commit message”
5.You can commit your changes to the svn server using the command: git svn dcommit
( If failed ,you may need to run firstly to check if conflict: git svn rebase ,  if conflicts occur, solve the conflicts, and then run: git svn dcommit )

Remember the Golden rule: you should always working on a local branch instead of the master, cause in GIT, it is not allowed to push/dcommit project which is not based on the latest version.  That’s to say, if you checkout the project, and working on the master, and modified file A, but someone modified the file A and dcommit before you dcommit your modification, then you will end with failure by push/dcommit your master.  So the recommend way is to work on a local branch:

git checkout -b story1

(it create a local branch story1, and checkout the branch)

then working on the branch, modify your project files, and commit on the branch.
If commit failed, need to merge changes from your topic branch (story1) into the master branch, and commit from the master branch.   Here’s the process to merge and commit:

5.1) Ensure the master branch is up to date

git checkout master

git svn rebase

5.2) Then merge your topic branch(story1) into master :

git merge story1

5.3) then commit the merged version on the master

git svn dcommit

5.4) go back to story1 branch, and working on other new features:

git checkout story1

 

Some tips on using git:
Q: gitk show unicode character correctly. how to solve it ?

A:echo “export LESSCHARSET=utf-8” > $HOME/.profile
git config –global gui.encoding utf-8git config –global i18n.commitencoding utf-8git config –global i18n.logoutputencoding gbkset LESSCHARSET=utf-8( on windows use set instead of export)

Q: how to show svn info for local git repos:

A: git svn info

Q: if git modifies files randomly,
A: caused by end of line. just set the core.autcrlf property to false:for unix:git config –global core.autocrlf inputgit config –global core.safecrlf true
for windowsgit config –global core.autocrlf falsegit config –global core.safecrlf true

Q: How to fix un-committed mistakes

If you’ve messed up the working tree, but haven’t yet committed your mistake, you can return the entire working tree to the
last committed state with
$ git reset –hard HEAD

Q: Fixing a mistake with a new commit.

Creating a new commit that reverts an earlier change is very easy; just pass the git revert command a reference to the bad
commit; for example, to revert the most recent commit:
$ git revert HEAD

This will create a new commit which undoes the change in HEAD. You will be given a chance to edit the commit message for the new commit.
You can also revert an earlier change, for example, the next-to-last:
$ git revert HEAD^git revert -n HEAD

 

Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)