Combine local Git commits into one commit for git-svn

梦想与她 提交于 2019-12-03 01:43:21

问题


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?


回答1:


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.




回答2:


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)




回答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         *---*---*---*---*



回答4:


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.



回答5:


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




回答6:


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



来源:https://stackoverflow.com/questions/1408381/combine-local-git-commits-into-one-commit-for-git-svn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!