Combine local Git commits into one commit for git-svn

后端 未结 6 1266
野的像风
野的像风 2021-01-30 09:16

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

相关标签:
6条回答
  • 2021-01-30 09:50

    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

    0 讨论(0)
  • 2021-01-30 09:52

    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         *---*---*---*---*
    
    0 讨论(0)
  • 2021-01-30 09:54
    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.

    0 讨论(0)
  • 2021-01-30 09:58

    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)

    0 讨论(0)
  • 2021-01-30 10:01

    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

    0 讨论(0)
  • 2021-01-30 10:02

    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.
    
    0 讨论(0)
提交回复
热议问题