简体   繁体   English

SVN 到 Git 迁移后重命名主干文件夹

[英]Renaming trunk folder after SVN to Git Migration

I have 30 some projects which I migrated to Git, from SVN.我有 30 个从 SVN 迁移到 Git 的项目。

However, when I browse the folder structure, I still see the trunk folder there in each project.但是,当我浏览文件夹结构时,我仍然看到每个项目中的主干文件夹。 Is there a way to remove this quickly and automatically?有没有办法快速自动地删除它?

Here is my svn folder structure, note that the repository itself does not have trunk, but the projects do:这是我的 svn 文件夹结构,请注意存储库本身没有主干,但项目有:

--MyRepository
  --Project1
    --trunk
      -- files
  --Project2
    --trunk
      -- files
  --Project3
    --trunk
      -- files
  --Project4
    --trunk
      -- files
  --Project5
    --trunk
      -- files
  -- ..

And this is what I want in my Git repository:这就是我想要的 Git 存储库:

--MyRepository
  --Project1
    -- files
  --Project2
    -- files
  -- ..

Thanks in advance.提前致谢。

PS: I thought I could share the commands which I use to migrate. PS:我想我可以分享我用来迁移的命令。 There it goes:它是这样的:

mkdir gitRepo && cd gitRepo
git svn init http://bla/svn/myRepo --no-metadata
git config svn.authorsfile ../authors.txt
git svn fetch

If you migrate correctly, then it should be no trunk folder.如果迁移正确,那么应该没有trunk文件夹。 See --stdlayout of the git svn .请参阅git svn --stdlayout So, you have three options:所以,你有三个选择:

  1. Redo migration correctly (easiest, but will affect git repo users if any).正确重做迁移(最简单,但会影响 git repo 用户(如果有)。
  2. Re-carve git history using filter-branch or something similar (should be faster than first one and doesn't need original svn repos, but will affect git repo users if any).使用filter-branch或类似的东西重新雕刻 git 历史(应该比第一个更快,不需要原始 svn repos,但如果有的话会影响 git repo 用户)。
  3. Just move folders and commit (easiest and safest, but the trunk folder will stay in the history forever).只需移动文件夹并提交(最简单和最安全,但主干文件夹将永远保留在历史中)。

How to migrate repo properly.如何正确迁移 repo。 As I understand you have a svn repo structure like this:据我了解,您有一个像这样的 svn repo 结构:

/
/projectA
/projectA/trunk
/projectA/branches/...
/projectB
/projectB/trunk
/projectB/branches/...

So you should do two migrations, creating two git repositories, for each project:所以你应该做两次迁移,为每个项目创建两个 git 存储库:

 git svn clone --stdlayout full/svn/repo/url/projectA
 git svn clone --stdlayout full/svn/repo/url/projectB

The thing is - svn doesn't have any idea about trunk and braches, all it understands is a folder.问题是 - svn 对主干和分支一无所知,它所理解的只是一个文件夹。 When you migrate to git, you should know your svn repo structure and accordingly map folders to branches.当你迁移到 git 时,你应该知道你的 svn repo 结构并相应地将文件夹映射到分支。

So, here it goes.所以,它来了。

The command which does the magic is:执行魔术的命令是:

git filter-branch -f --index-filter \
    'git ls-files -s | sed "s-/trunk/-/-" |
            GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
            git update-index --index-info &&
     mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' af117ec86a30ba6676571cd1f73083c5cfbec0bd..HEAD

note the commit tag before ..HEAD , that should be either second or third earliest commit tag that you should enter.请注意..HEAD之前的提交标记,它应该是您应该输入的第二个或第三个最早的提交标记。 If you enter the first, you get an error.如果输入第一个,则会出现错误。

To find out the commit tag of the earliest commit, simply use:要找出最早提交的提交标签,只需使用:

git log

and scroll down as much as you can, there you will see the earliest commits.并尽可能向下滚动,在那里您将看到最早的提交。 Take the second or third.采取第二个或第三个。 It's done.完成。

No, you should structurize the folder root as you want at first and then you should map the root.不,您应该首先根据需要构造文件夹根目录,然后再映射根目录。 A Proper way of doing.正确的做法。

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

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