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

后端 未结 4 583
梦如初夏
梦如初夏 2021-02-09 06:49

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 mus

4条回答
  •  温柔的废话
    2021-02-09 07:13

    This might be worth a try, I'm a relative newbie but this is what I'm doing for now:

    Create a clone of the remote svn repository:

    # clone svn repository
    git svn clone ....
    

    Create a normal git repository (clone of the clone):

    # clone the clone :)
    git clone /path/to/original/clone
    git checkout -b working
    

    You can now work in the second clone as though it were a normal git repository (essentially it is):

    # commit changes, whatever you like
    git ci
    ...
    

    To push your changes back to the central SVN repository go back to the first clone and:

    # pull and flatten changes
    git pull --squash /path/to/working/clone
    

    The --squash parameter means that all the commits that are pulled in are merged into one commit. That commit is not committed immediately so you can then:

    git ci
    git svn dcommit  
    

    The last step then pushes everything as one single commit.

    Edit - I wouldn't normally recommend using --squash in other circumstances but note that the working repository retains the full complete history (it's immune to the squash) but what you send upstream is squashed into a single clean commit which is what is needed in this case. I believe it to be a reasonable compromise.

提交回复
热议问题