如何使用 git-svn 使 svn:external 保持最新?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/350651/
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 06:00:38  来源:igfitidea点击:

How do I keep an svn:external up to date using git-svn?

svngitversion-controldvcs

提问by James A. Rosen

Treating my repository as a SVN repo, I get:

将我的存储库视为 SVN 存储库,我得到:

svn co http://myrepo/foo/trunk foo
...
foo/
  bar/
  baz/ -> http://myrepo/baz/trunk

Treating it as a Git repo, I get:

将其视为 Git 存储库,我得到:

git svn clone http://myrepo/foo --trunk=trunk --branches=branches --tags=tags
...
foo/
  bar/

I can clone baz to my local machine elsewhere and add a symlink, but that's just a hack. Is there a way to have git svn rebaseautomatically pull in those changes when it updates everything else, just like svn updoes?

我可以将 baz 克隆到其他地方的本地机器并添加符号链接,但这只是一个技巧。有没有办法git svn rebase在更新其他所有内容时自动引入这些更改,就像svn up那样?

采纳答案by James A. Rosen

The solution I ended up using was just to symlink to other git-svnclones on my local box. This worked pretty well: it allows me to commit changes back, and it allows me to make local changes on project A just to get them into project B.

我最终使用的解决方案只是符号链接到git-svn我本地机器上的其他克隆。这工作得很好:它允许我提交更改,并且它允许我对项目 A 进行本地更改,只是为了让它们进入项目 B。

回答by Paul

The best means of integrating svn externals with git-svn that I've seen is this script, which clones your externals into a .git_externals/ directory and creates the symlinks and exclude files you need. I find this a simple and direct solution. YMMV.

我见过的将 svn externals 与 git-svn 集成的最佳方法是这个脚本,它将您的外部设备克隆到 .git_externals/ 目录并创建符号链接并排除您需要的文件。我发现这是一个简单而直接的解决方案。天啊。

Here is an older overviewof other options for dealing with svn externals with git-svn. To me they look a little over-complicated and liable to break under subsequent Git use.

这是使用 git-svn 处理 svn externals 的其他选项的旧概述。对我来说,它们看起来有点过于复杂,并且在随后的 Git 使用中容易崩溃。

回答by tuomasjjrasanen

I just wrote a short script which checkouts all svn:externalsof the current HEADto the root directory and excludes them from the git repository.

我刚刚编写了一个简短的脚本,它将所有svn:externals当前文件检出HEAD到根目录并将它们从 git 存储库中排除。

Place it to .git/hooks/post-checkoutand it will keep those external checkouts up to date whenever the working tree changes, for example due to git svn rebaseor git-checkout.

将它放置到.git/hooks/post-checkout,它会在工作树更改时使这些外部结帐保持最新,例如由于git svn rebasegit-checkout

#!/bin/bash
set -eu

revision=$(git svn info | sed -n 's/^Revision: \([1-9][0-9]*\)$//p')
git svn -r${revision} propget svn:externals | head -n-1 | {
    while read checkout_args
    do
        checkout_dirname=$(echo ${checkout_args} | cut -d' ' -f3)
        svn checkout ${checkout_args}
        if [ -z $(grep ${checkout_dirname} .git/info/exclude) ]
        then
            echo ${checkout_dirname} >> .git/info/exclude
        fi
    done
}

回答by Marc Liyanage

I also made a script (both Perl and Ruby variants available) that does this for me, it's at http://github.com/liyanage/git-tools/.

我还制作了一个脚本(Perl 和 Ruby 变体都可用)来为我做这件事,它位于http://github.com/liyanage/git-tools/

  • Recursively checks out all svn:externals
  • Can be run repeatedly in case the clone of a large repository aborts halfway through. Happened to me a lot. It picks up where it left off.
  • Adds all svn:externals entries it finds and processes to .git/info/exclude
  • Adds all svn:ignore entries it encounters to .git/info/exclude
  • Can be run regularly after the first run to do the svn:rebase in all cloned sub-sandboxes, discover new externals and new svn:ignores
  • 递归地检查所有 svn:externals
  • 可以重复运行,以防大型存储库的克隆中止。发生在我身上很多。它从停止的地方开始。
  • 将它找到并处理的所有 svn:externals 条目添加到 .git/info/exclude
  • 将遇到的所有 svn:ignore 条目添加到 .git/info/exclude
  • 可以在第一次运行后定期运行以在所有克隆的子沙箱中执行 svn:rebase,发现新的外部和新的 svn:ignores

Update: I am no longer maintaining this script. Its functionality for recursively cloning and updating an SVN repository, as well as other git-related features, is available in this newer project that I am actively maintaining: http://liyanage.github.com/git-tools/

更新:我不再维护这个脚本。它用于递归克隆和更新 SVN 存储库的功能以及其他与 git 相关的功能在我正在积极维护的这个新项目中可用:http: //liyanage.github.com/git-tools/

回答by rsenna

Just for the record: I followed thissuggestion and tried using SmartGitfor dealing with svn:externals.

仅供记录:我遵循了这个建议并尝试使用SmartGit处理svn:externals.

SmartGit is by far the best GUI client I've ever seen for Git. Regarding svn:externals, it not only correctly fetches them, but also presents the option of doing a "fast snapshot" (read-only, HEAD-only clone) of external repositories.

SmartGit 是迄今为止我见过的最好的 Git 图形用户界面客户端。关于svn:externals,它不仅可以正确获取它们,而且还提供了对外部存储库进行“快速快照”(只读、仅 HEAD 克隆)的选项。

Unfortunately it is not free for commercial use (and I found the license price a little bit too high - yes I'm a cheapskate). It may be used for free for non-commercial purposes though.

不幸的是,它不能免费用于商业用途(我发现许可价格有点太高了 - 是的,我是个小气鬼)。不过,它可以免费用于非商业目的。

回答by TCS

Here's what I've done.

这就是我所做的。

First I created an empty SVN repo (for the same root as the git):

首先,我创建了一个空的 SVN 存储库(与 git 具有相同的根):

svn checkout --depth empty http://path/to/repo .

This created empty svn repo in the git root. The point is that is contains the SVN externals properties.

这在 git root 中创建了空的 svn repo。关键是它包含 SVN 外部属性。

Next I simply check only the externals (I placed in PATH cygwin tools):

接下来我只检查外部(我放置在 PATH cygwin 工具中):

svn propget svn:externals | sed -e 's/ / .\//' | sed -e 's/\'//g' | xargs -L1 svn co

回答by opekar

try this python script https://bitbucket.org/nytmyn/gitsvnext/overview

试试这个 python 脚本https://bitbucket.org/nytmyn/gitsvnext/overview

to checkout svn externals run following in your git repository

结帐 svn externals 在您的 git 存储库中运行

python /../gitsvnext/run update

run this to know what to put to .git/info/exclude

运行它以了解将什么放入 .git/info/exclude

python /../gitsvnext/run list

回答by Dmitry

I decided to write a "simple" perl script to handle all this stuff for me. I've put it recently to github, try it out, maybe it would help: http://github.com/sushdm/git_svn_externals/.

我决定编写一个“简单”的 perl 脚本来为我处理所有这些事情。我最近把它放到了 github,试试看,也许它会有所帮助:http: //github.com/sushdm/git_svn_externals/

It essentially does git-svn clone for all externals found, and it looks for them recursively, clones, symlinks them in proper places and excludes all .git_externals dirs and symlinks so that you can still use 'git svn dcommit'.

它基本上为找到的所有外部对象执行 git-svn 克隆,并递归查找它们,克隆它们,将它们符号链接到适当的位置,并排除所有 .git_externals 目录和符号链接,以便您仍然可以使用“git svn dcommit”。

Good luck.

祝你好运。