28

Currently, when I run git svn dcommit git creates a separate commit in SVN for every local commit I've made since last syncing with SVN. Is there any way for dcommit to instead combine all my recent local commits into one commit for SVN?

Timo Tijhof
  • 10,032
  • 6
  • 34
  • 48
MacRae Linton
  • 293
  • 3
  • 6

6 Answers6

18
git rebase remotes/trunk --interactive 

should bring you to the menu where you can pick commits or squash them all into 1 commit in order to avoid polluting your svn repository. This is a really good (but short) resource on working with git-svn.

Restore the Data Dumps
  • 38,967
  • 12
  • 96
  • 122
  • This seems like a very good solution. I don't understand what the effect of remotes/trunk is in the command, the end result is that all my commits are squashed inside of master. I was hoping they would only be squashed in sending to SVN. It is necessary to commit to SVN after the squashing is done. – MacRae Linton Sep 18 '09 at 16:48
  • @MacRae Linton: All your commits have to be squashed in master. If they weren't git would have no way of keeping the git and svn repositories in sync. When you rebase to pull the latest changes svn would have one commit but in git you'd have n commits. – Restore the Data Dumps Sep 18 '09 at 17:18
  • @Jason Punyon: The issue I am running into is that after squashing commits in master, it becomes difficult to merge master with my developing branch again. Pretty much all my changes become merge conflicts, which is a huge pain to deal with. Is this an unavoidable consequence of keeping my developing branch separate from the squashed master? – MacRae Linton Oct 15 '09 at 01:06
  • @MacRae Linton: Yeah that's a problem. It's not recommended to use rebase for commits that have already been replicated elsewhere. Rewriting history that way causes the problem you describe with the merge conflicts... – Restore the Data Dumps Oct 15 '09 at 01:30
  • @Jason: So, in the end, there is no way to maintain separate histories for git and svn. If I want an abridged history for svn, I need to have that history be the history in git as well? – MacRae Linton Oct 15 '09 at 18:37
  • Does not work for me. I think it has to be "refs/remotes/trunk" – Martin Konicek Mar 01 '11 at 18:11
17

No, but you can squish all the commits together pretty easily. For the following example, I'm going to assume you're on the master branch corresponding to the remote trunk branch and that you want to squish all local commits together:

git tag local # create a temporary tag
git reset --hard trunk
git merge --squash local
git commit # write your single commit message here
git svn dcommit
git tag -d local # delete the temporary tag named local

Instead of using a temporary tag you could also just use the reflog (i.e. use master@{1} in place of local)

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
3

When I work with git-svn and want a series of git commits to show up as a single commit, I work on a topic branch and then do a non-fast-forward merge into master before dcommit-ing.

First, rebase your branch against svn and make sure local master is up-to-date:

git svn rebase && git push . remotes/trunk:master

Then switch to master, merge and dcommit:

git checkout master
git merge <branch> --no-ff -m "Message you want in svn"
git svn dcommit

This will show up as a single commit in Subversion but you will still have your local history that got you to that commit.

                                       +--- Merge commit
                                       V
svn trunk  *---*---*-------------------*--- --- ---
                    \                 /
topic branch         *---*---*---*---*
dahlbyk
  • 75,175
  • 8
  • 100
  • 122
3

A simpler way could be (if you have multiple commits piled up on your local system):

git reset <hash tag of commit till which u need to combine>
git commit -am "your message"  // This will create one clubbed commit of all the commit till the hash tag used.
Akash Agrawal
  • 4,711
  • 5
  • 28
  • 26
2

This worked for me--squashed several commits into one commit and then dcommitted to svn:

http://www.gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html

Baq Haidri
  • 21
  • 1
0

that is not working for me. I use merge --no-ff --no-commit but after commit, I got:

svntrunk                        54f35e4 [trunk: ahead 336] release 1

dcommitting to trunkwill commit all 336 commits.

resetting, tagging, and squashing as described in answer #2: Combine local Git commits into one commit for git-svn will work, but on next "merge" you will have some trouble to get all commits together again!

the one and only that is working for me:

git checkout -tb svntrunk remotes/trunk
git merge --no-commit --squash master

to get all commits from master to svn without loosing history for future merging with the same command

~Marcel

Community
  • 1
  • 1
childno͡.de
  • 4,679
  • 4
  • 31
  • 57