开发者

Repair links between moved files in Mercurial

开发者 https://www.devze.com 2023-01-30 07:41 出处:网络
Over the course of having this repo (originally SVN) I\'ve not been to good with keeping file links together. I\'ve changed IDE\'s twice, split the project into Netbeans modules, and mavenized the pro

Over the course of having this repo (originally SVN) I've not been to good with keeping file links together. I've changed IDE's twice, split the project into Netbeans modules, and mavenized the project over its time. Most of the file history is lost, 开发者_开发技巧mainly because during mavenizing I deleted the entire trunk, committed, copied over the maven project, and committed. Not exactly the best idea, as I later found out all history reset to that point. Its gotten so bad that a repository stats program is useless since it says I have 50,000 lines of code invested instead of ~8,000.

Is there any way to fix all the broken file histories? I have access to SVN and Git if Mercurial can't do it


Hrm, and the time you did your delete and copy you'd've been fine had you just done hg addremove --similarity 90 which says "remove everything that's gone, add everything that's new, and if they're 90% similar to one another count is as a rename".

Now that that opportunity has passed there's no way to move one w/o re-writing your repository, which invalidates all the clones out there in the wild as all the node ids (hashes) change. If that's okay and you have a largely linear history you can probably get by with something like this:

hg export --output "../patch-%n.patch" 0:tip  # exports every changeset to a patch file
cd ..
hg init newrepo
cd newrepo
hg import --similarity 90 ../patch*

That takes a linear history from your first commit to your last (excluding branches and other heads, etc.) exports them to patches, creates a new empty repo, and imports the changesets using the rename detection feature.

This is a pretty drastic act so make sure it's really worth it to you and keep your old repo around for good measure.

0

精彩评论

暂无评论...
验证码 换一张
取 消