简体   繁体   English

如何解决带有移动文件的 git-svn rebase?

[英]How to resolve a git-svn rebase with moved files?

I have a problem rebasing my long-lived branch (called 'metrics') onto the latest version of my 'trunk' branch.我在将长期存在的分支(称为“指标”)重新定位到“主干”分支的最新版本时遇到问题。 The goal is to get my changes rebased, and then committed back to SVN.目标是让我的更改重新定位,然后提交回 SVN。

The rebase has 75 steps right now, and step 40 is applying significant source code changes onto files that were relocated in svn.变基现在有 75 个步骤,第 40 步将对在 svn 中重新定位的文件应用重大源代码更改。

Specifically, I made lots of changes to files in /java/**/*.java.具体来说,我对 /java/**/*.java 中的文件进行了大量更改。 Meanwhile, these files were relocated to: /src/main/java/**/*.java.同时,这些文件被重新定位到:/src/main/java/**/*.java。

git status shows: git状态显示:

# Not currently on any branch.
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#   added by them:      java/StripesResources.properties
.... (many files like this)
#   both deleted:       src/StripesResources.properties
.... (many files like this)
#   added by us:        src/main/java/StripesResources.properties
.... (many files like this)

There are over 900 files in this state, what do I do to merge them?这个state里面有900多个文件,怎么合并呢? Not all of them have substantial changes.并非所有这些都有实质性的变化。

I tried moving / copying the 'them' versions of the files (my changes) onto the 'us' locations (where they should be), but that didn't seem to work.我尝试将文件的“他们”版本(我的更改)移动/复制到“我们”位置(它们应该在的位置),但这似乎不起作用。

Should I use 'git mv' in this case?在这种情况下我应该使用'git mv'吗?

Thanks.谢谢。

This might not the best solution as it involves history revision.这可能不是最好的解决方案,因为它涉及历史修订。 You could use git filter-branch to move the 'metrics' branch's /java/**/*.java files into /src/main/java/**/*.java , then conduct the rebase.您可以使用git filter-branch将 'metrics' 分支的/java/**/*.java文件移动到/src/main/java/**/*.java中,然后进行变基。 First, backup your repository.首先,备份您的存储库。 Then try something like this:然后尝试这样的事情:

git checkout metrics
git filter-branch --index-filter '
    git ls-files -s |
        perl -pe "s{\t/java/\"?}{\t/src/main/java/}" |
        GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&
    mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE
' HEAD

That will rewrite your metric branch's history, effectively moving every file whose path begins with /java/ to /src/main/java .这将重写您的度量分支的历史记录,有效地将路径以/java/开头的每个文件移动到/src/main/java If you want just the java files in those paths, modify the perl statement accordingly.如果您只需要这些路径中的 java 文件,请相应地修改perl语句。 Mucking around with git ls-files -s | perl -pe <substitution>乱搞git ls-files -s | perl -pe <substitution> git ls-files -s | perl -pe <substitution> at various points in your history will help you determine what you need. git ls-files -s | perl -pe <substitution>在你历史的不同点将帮助你确定你需要什么。

A a Thing That Can Be Done With Git (tm), the above is awfully drastic. A Thing That Can Be Done With Git (tm),以上内容非常激烈。 All the same, it should solve the file name issue.尽管如此,它应该可以解决文件名问题。 Having attempted a few long-divergent branch merges before, this particular problem will not be your last.之前尝试过一些长期分歧的分支合并,这个特殊问题不会是你的最后一个问题。 If your workflow generates highly divergent, long-term branches regularly, you might consider changing it.如果您的工作流程定期生成高度发散的长期分支,您可能会考虑更改它。

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

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