Team using git/git-svn to share work and only occasional svn commits - git-svn

I am new to git but read this article by Martin Fowler where he describes a setup where a team works using git/git-svn and only occasionally commit to the central svn repo.
Can somebody point to an article or screen-cast (or off course answer how to do this) describing the workflow, commands and pitfalls?

Have a look at http://blog.emmanuelbernard.com/2010/05/git-how-my-life-has-improved-since-last-month-when-i-used-svn/comment-page-1/#comment-2248
The summary is that you have one repo with git-svn. Everybody who wants to work with git just clones that repository and works with plain git. Than on the git-svn repo somebody from time to time fetches commits from subversion, merges new commits from git and dcommits them back to svn (rolled up, it's not possible to transfer individual commits both ways).

Related

Use git-svn with multiple svn repos and branches

I have a svn branch that I had been working on and decided to start using git-svn to work locally. Now I have two problems. I want to move my work into another svn repository (on the same host) but I'd first like to merge the latest work from trunk. How would I do this with git-svn? Also, how would I continue my work in a separate svn-repo while continually merging work from the original repo? Also, I don't want to checkout the entire history from the original trunk because the project is rather huge. I am new to git and to git-svn, though I've taken a crash course in git branching and I feel confident enough to use advanced commands like rebase and cherry-pick. I mainly need to know how to apply these concepts thru git-svn. Do the svn repos get setup as a git remote somehow? Are there good resources on the net explaining how it works? Any guidance is much appreciated.
Create your Git repo with git svn init -s <url>.
git config --edit, add several svn-remotes for each of your Subversion repos. Later you'll use the -R option to all git-svn commands to select which svn-remote to use.
Tweak svn-remote branch mappings as needed. Keep in mind that the default refs/remotes/* namespace specifies remote branches — not Git remotes. (You'll have just a single git remote named . which I don't recommend pushing/pulling to/from).
You can easily design your remote branches namespace to keep branches from different Subversion repos separated (e.g. refs/remotes/repoA/*, /refs/remotes/repoB/* etc).
git svn fetch. This has options to scan history only partially, e.g. starting from a specific revision. Please read the manpage on instructions how to do this.
You can also ignore specific paths and/or branches here.
Work with Git as usual, trying to keep your commits as linear as possible. Rebase often. Merge commits are fine (git-svn will even set svn:mergeinfo property), but holy cow be careful (and read the manpage for caveats). Understand that Git commits with git-svn-id tags are immutable, and push -f won't save you. For example, it's forbidden to amend or rebase already dcommit'ed changes.
Are there good resources on the net explaining how it works?
By far the best resource is the manpage. The next after it is git-svn source.

Working with GIt without branches

I am trying to work with GIT, without creating private branches.
What that means is I directly work on my cloned repository (master)
Now, Is that the right way to use GIT? I run into many issues related to updating my repository (GIT PULL / GIT FETCH). And most of the time, I am not able to use GIT Merge.
Is there a particular way in which i can use GIT MERGE, GIT PULL, and GIT FETCH. That will help me?
Looks like the best way to work with GIT is have branches.
Branch 1
GIT Commit
GIT PUSH
GIT MERGE master ( to fetch the newer changes)
Branch 2
GIT Commit
GIT PUSH
master
GIT Merge branch1
GIT Merge branch2
I dont think there any other way. Please correct me if i am wrong?
Jan Krueger's extended cheat sheet will help you cover the basics, and will expose you some common commands for using git.
IMO, git is a brilliant DVCS. If you have time; take a look at the structure of git and try to catch the ideas behind its design. For example this Tech Talk by Linus Torvalds.
Note: It looks like you are missing some core ideas behind using git, so please try to learn general approach of git before tackling with commands.
Note 2: As being a stalker, you seem to have general problems with git. So I repeat my advice once more. Learn basics, complete a tutorial, read/listen/watch a few useful source from notable people about git.
Also read about git stash. It saves your local uncommitted changes so you can pull cleanly. Then run git stash pop to replay those changes on top.

Commit git-svn changes to SVN repo

we have a central SVN repo in our company. I use git-svn on my laptop to be able to use a repo, when I'm not connected to the company network.
Now I was 3 weeks on a business trip and committed a lot to my local Git repo. There were also many commits to the SVN repo.
When I try "SVN Rebase" I have to edit conflicts in each of my Git changesets. What I would like to do is just to commit all of my local changes at once and then edit conflicts only once.
I'm fairly new to Git, so I don't know how this is done properly and if this is the best way.
I use TortoiseGit on Windows, so up to now I didn't really care about the command line.
Thanks for your help.
Once you go through conflict resolution in git-svn rebase once you are in a new tree with new commits that include your resolutions. A future git-svn rebase will not encounter the same problems (unlike repeated merges, which is where rerere comes in handy).
If by "commit all my local changes at once" you mean you want to fold all of your commits into a single commit in git (and later SVN) then you can use git rebase -i to "squash" all of your commits into a single commit. You should not include any revisions that have already been sent to SVN with dcommit in that rebase -i because you are rewriting history. You will still have to resolve conflicts when you git-svn rebase just like you would if you were using only SVN and did svn update.

git-svn branch - How to keep branch in sync with trunk?

There are plenty of questions about git-svn workflow, but I haven't been able to figure this one out:
This section of the svn book talks about a common practice with SVN: you make a branch, and you keep merging changes from the trunk as the trunk gets updated, so that the branch always includes the latest changes.
I did git svn branch to create a branch on svn and then set up a tracking branch to work on it. These questions cover the process pretty well.
Now suppose there were changes made to the trunk, which I now want to merge into the branch. What is my best option? Note that I need to keep git-svn happy, and not mess up the work of people using the branch with subversion, so just doing a rebase would probably not work.
This question seems to talk about a similar situation, although it's pretty old, and I'm not sure what the bottom line there was - it seems to suggest I should git checkout master and then git rebase mybranch, but that can't be right.
I suspect the the answer should be something that has the effect of svn merge, preferably with setting the mergeinfo property, but alas, there is no git svn merge...
I don't really understand how this simple question was left unanswered for more than a week, with only 13 views so far. I guess it was my fault, bad question writing.
Anyway, I figured it out myself. Short version: just use git merge instead of git rebase.
My confusion came from using git rebase when syncing a branch with the changes in master. When working on local branches, this usually works great, and keeps the history clean. However, you should not rebase commits that you have pushed to a public repository, and the subversion repository is (apparenly) public enough. git merge, on the other hand, works beautifully, and doesn't have any problem.
So, the long answer is: when you want to merge the latest changes in the trunk into the svn branch you're tracking, just do:
git merge master
# Handle conflicts, git add when you're done
git commit
git svn dcommit
This will keep your branch in sync with trunk, but will not set mergeinfo, so you probably should not mix svn merge with this kind of practice.

How to dcommit only selected patches with git svn?

I have a number of locally committed patches in my git-svn repo which I haven't yet commited to our svn repo. A normal "git svn dcommit" will commit all of these patches to svn. I would like to commit only some of my patches (simple bug fixes), but not others (untested major changes). How can I do this with git svn?
I've been following the procedure here:
http://fredericiana.com/2009/12/31/partial-svn-dcommit-with-git/
If you're comfortable rebasing, it works pretty well.
Here's what I ended up doing. The starting point is the "master" branch synced with svn, with all of my local patches on top.
Create a new branch (wip = Work In Progress).
git branch wip
This makes a copy of the current branch, including all patches not yet committed to svn. The current branch will stay as "master" and will not be changed.
Remove the unwanted local patches from "master" with a rebase:
git rebase -i HEAD~10
Now the "master" branch has patches you can safely commit:
git svn dcommit
The "wip" branch now has the major changes which aren't yet ready for sharing. Actually, I want them to stay there and this is where I would stop. It's possible to do the svn dcommit from the "wip" branch once everything is finalized. But for completess' sake, and to answer the original question, there's a final step:
Pull the uncommitted changes back to the "master" branch using git cherry-pick and finally remove the useless branch with git branch -d wip.
With git, you're not actually supposed to operate on single changesets. The best approach I know is to create local branches for any non-trivial work. This way, your untested major changes will end up in different branches of your git repository, and you'll be able to differ them quite easily.
If this is the problem you have at the moment you can probably create create a new branch from the point you last updated from svn and then use git-cherry-pick to transfer your simple bug fixes to this new branch, from which you can then dcommit to svn.
From a more long-term point of view it's best to have your own "master" branch made from subversion trunk, and then either:
Rebase all your branches every time you update from svn, then merge those you want to get to svn to your master and dcommit from there.
Merge stuff from svn using regular git-merge, and then merge stuff to your master for dcommits by git diff ..my_branch | patch -p1, which will eliminate history that git-svn can't handle. This approach is more complicated for the final merging but allows you to merge stuff between branches (and possibly other people) in git itself.