Git-SVN:从集中式 SVN 服务器更新 Git 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16857063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:18:10  来源:igfitidea点击:

Git-SVN: Update Git repo from centralized SVN server

gitgit-svngit-pullgit-fetch

提问by Jacob Krieg

I'm working on a project for which everyone uses SVNas a centralized server and everybody pushes the changes they do on that server. I want to use Gitlocally and I'm pretty new to git svn. I did a git svn cloneof the repository with git svn clone -r HEAD https://svn.repo/app/branchan I want to do an update through git.

我正在开发一个项目,每个人都将其SVN用作中央服务器,并且每个人都在该服务器上推送他们所做的更改。我想在Git本地使用,而且我对git svn. 我做了一个git svn clone存储库,git svn clone -r HEAD https://svn.repo/app/branch我想通过 git 进行更新。

I need a 'git pull like' command but to pull from a specific revision of the SVN server repo. Also is there a 'fetch like' command to fetch from a specific revision of the SVN server repo?

我需要一个 'git pull like' 命令,但要从 SVN 服务器存储库的特定版本中提取。还有一个'fetch like'命令可以从SVN服务器存储库的特定版本中获取吗?

I don't have any .svnfolders in my cloned project and git remotedoesn't give me anything. However I did a git config -land I get the SVN server's URL, so somehow I'm linked with the SVN server. I don't know how to fetch or pull though.

我的.svn克隆项目git remote中没有任何文件夹,也没有给我任何东西。但是我做了一个git config -l,我得到了 SVN 服务器的 URL,所以我以某种方式与 SVN 服务器链接。我不知道如何获取或拉动。

Thanks!

谢谢!

回答by bentolor

Best way to work on a Subversion Repository via Git:

通过 Git 处理 Subversion 存储库的最佳方式:

  1. git svn init -s https://svn.repo/app/ myrepoassuming that under https://svn.repo/app/the repo contains the standard /trunk, branchesand tagssubdirectories
  2. Do a git svn fetchin myrepo until no more commits are fetched (may take quite some time and sometimes aborts under Windows).
  3. Checkout a specific Subversion branch or trunk via git checkout -b trunk remotes/trunk
  1. git svn init -s https://svn.repo/app/ myrepo假设在https://svn.repo/app/ 下,repo 包含标准/trunk,branchestags子目录
  2. git svn fetch在 myrepo 中执行,直到不再获取提交(可能需要相当长的时间,有时在 Windows 下会中止)。
  3. 通过以下方式签出特定的 Subversion 分支或主干 git checkout -b trunk remotes/trunk

Then you can simply browse, hack and commit into your Git Repo containing all Subversion commits and branches.

然后,您可以简单地浏览、修改并提交到包含所有 Subversion 提交和分支的 Git 存储库。

  • To pull in new commits from SVN use git svn rebase
  • To push your local commits into SVN use git svn dcommit
  • 要从 SVN 中提取新的提交,请使用 git svn rebase
  • 将您的本地提交推送到 SVN 使用 git svn dcommit

To jump to a specific Subversion revision you only need to browse the history via git logand search for a commit mirroring the according subversion commit. You can easily spot the Subversion revision in the git-svn-id:line of the commit message. The just use a git checkout <commithash>to explicitly checkout that version.

要跳转到特定的 Subversion 修订版,您只需浏览历史记录git log并搜索反映相应 Subversion 提交的提交。您可以轻松地git-svn-id:在提交消息的行中发现 Subversion 修订版。只需使用 agit checkout <commithash>显式检出该版本。

回答by Guillaume Darmont

A good start :

一个好的开始:

To fetch new svn commit into your local repo : git svn rebase

获取新的 svn commit 到你的本地仓库: git svn rebase

To push your local commit to SVN : git svn dcommit

将您的本地提交推送到 SVN : git svn dcommit

You will probably have to use git stashand git stash pop, before using the two commands above when your working copy has uncommited changes.

当您的工作副本有未提交的更改时,您可能必须在使用上面的两个命令之前使用git stashand git stash pop