简体   繁体   English

如何在一次提交中提交到SVN和GIT?

[英]How to commit to SVN and GIT in one commit?

Currently we're moving from SVN to GIT in my company. 目前,我们公司正在从SVN迁移到GIT。

We need to make both repositories the same for the coming few months, I need to have a command or an other way which commits my work for SVN and GIT. 在接下来的几个月中,我们需要使两个存储库保持相同,我需要使用命令或其他方式来提交我对SVN和GIT的工作。

I there such a way? 我有这种方法吗?

Yes, it is. 是的。 Use git svn — it allows bidirectional manipulations between git and SVN. 使用git svn允许在git和SVN之间进行双向操作。

You commit to git using git commit and then push commits to SVN using git svn dcommit . 您可以使用git commit提交到git,然后使用git svn dcommit将提交推送到SVN。

If you gonna push commits from local git repo to some remotes first run dcommit because dcommit sends commits to SVN, creates SVN revisions and then rebases commits in git to synchronize git with SVN. 如果您要将提交从本地git repo推送到某些远程服务器,请先运行dcommit因为dcommit将提交发送到SVN,创建SVN版本,然后在git中重新提交提交,以将git与SVN同步。

When someone else adds new commits to SVN you fetch them into git and rebase using git svn rebase . 当其他人向SVN添加新提交时,您将它们提取到git中并使用git svn rebase

Actually this does not make much sense, as you make many advantages of having a local Git repo of a remote SVN repo void this way. 实际上,这没有多大意义,因为使用远程SVN存储库的本地Git存储库会带来很多好处,因此这种方式无效。 But if you really want to do this, just make an alias that does what you want. 但是,如果您真的想这样做,只需创建一个别名即可。 E. g. 例如 git config alias.committoboth '!ctb() { git commit "$@" && git svn dcommit; }; ctb' git config alias.committoboth '!ctb() { git commit "$@" && git svn dcommit; }; ctb' and then you can do stuff like git committoboth -m "my commit message" . git config alias.committoboth '!ctb() { git commit "$@" && git svn dcommit; }; ctb' ,然后您可以执行git committoboth -m "my commit message"

Instead you might also want to have a look at https://subgit.com/ . 相反,您可能还想看看https://subgit.com/ If you need to support Git and SVN for multiple users over a longer period, it might be better to do the synchronizing on the server which that tool says it does. 如果您需要在更长的时间内支持多个用户的Git和SVN,则最好在该工具说明的服务器上进行同步。

You cannot do it in one command unless you create a command to do it for you, as nativity git-svn does not have such command. 您不能在一个命令中执行此操作,除非您创建了一个命令来为您执行此操作,因为诞生git-svn没有这样的命令。

You can create an shell script file as git_svn which does groups all the command required by your workflow. 您可以将shell脚本文件创建为git_svn ,该文件对工作流程所需的所有命令进行分组。 And add this shell script to your system path: 并将此shell脚本添加到您的系统路径:

#!/bin/sh
git commit -m "$1"
git push origin
git svn dcommit --rmdir

To use it, you wold just do: 要使用它,您只需执行以下操作:

$ git_svn "my commit message"

References: 参考文献:

  1. Git svn fetch and then commit to remote git git svn获取并提交到远程git
  2. https://gist.github.com/rickyah/7bc2de953ce42ba07116 A simple guide to git-svn https://gist.github.com/rickyah/7bc2de953ce42ba07116 git-svn的简单指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM