Combine local Git commits into one commit for git-

2019-03-08 08:13发布

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?

6条回答
神经病院院长
2楼-- · 2019-03-08 08:38
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.

查看更多
虎瘦雄心在
3楼-- · 2019-03-08 08:45

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)

查看更多
何必那么认真
4楼-- · 2019-03-08 08:49

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

查看更多
\"骚年 ilove
5楼-- · 2019-03-08 08:55

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.
查看更多
迷人小祖宗
6楼-- · 2019-03-08 08:56

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         *---*---*---*---*
查看更多
何必那么认真
7楼-- · 2019-03-08 08:56

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

查看更多
登录 后发表回答