Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Squashing or editing some commits before doing git-svn dcommit?

I am working on a project in a subversion repository with a strict check-in policy which includes: Every commit to the trunk has to be reviewed by another developer and this must be mentioned in the commit message.

While working with git-svn I am making many incremental git check-ins that aren't reviewed. Their git commit messages reflect this.

What's the best way in which to use git-svn but follow the rules for the svn repository? Should I just squash all commits into a single svn commit? Can I rewrite the commit messages for each revision with the reviewer information? Could I "manually" move each individual change to the git master branch and modify the commit message of each before doing a git-svn dcommit?

like image 353
toholio Avatar asked Jul 23 '09 07:07

toholio


2 Answers

I work in a branch on git, then checkout master, git svn rebase and finally merge the branch into master.

At this point, git svn dcommit will put all the interim commits into svn one at a time with their original messages — not what's wanted! But if I use git commit --amend to change the merge's commit message from the standard merge message to something that fits our policy for svn commits, the dcommit will lump them all together as one under the new message. Win.

I've found that this doesn't seem to work if master hasn't changed over the lifetime of the branch — the commits just get fast-forwarded in, with no "merged branch" message — so it's best add the --no-ff flag to git merge.

Summary:

git checkout branch
<do work>
git checkout master
git svn rebase
git merge --no-ff branch
git commit --amend
<policy-compliant commit message>
git svn dcommit
like image 180
John Y Avatar answered Nov 05 '22 18:11

John Y


You can interactively rebase your local branch against the Subversion tracking branch which provides you with an opportunity to squash and amend the commit.

Next time you dcommit, dcommit will replay your history one commit at a time and this is what will be commited to Subversion.

Assumptions:

  1. Local branch is master
  2. Master is checked out
  3. Remote tracking branch is named git-svn
  4. git-svn is up to date

What to do:

$ git rebase -i git-svn

Your default editor will open with a list of commits in master to rebase against git-svn. You can pick, edit or squash the commit (Mix and match if desired).

After making your selection, another temporary file will open displaying commit messages for each of the commits you're rewriting. This is where you amend the commit message.

Caveats:

You're rewriting the history of your repository, exercise caution. It might be worthwhile experimenting with this behaviour until feel confident.

like image 40
Tate Johnson Avatar answered Nov 05 '22 17:11

Tate Johnson