开发者

In Mercurial, how do I pick specific files from a named branch to merge back with default?

开发者 https://www.devze.com 2023-01-04 22:16 出处:网络
I have a big named branch with a lot of changes. Some of these changes are non-destructive so I want to pick these specific files out first, and merge them with default as soon as possible. (Then late

I have a big named branch with a lot of changes. Some of these changes are non-destructive so I want to pick these specific files out first, and merge them with default as soon as possible. (Then later, the destructive changes are merged as well.)

In Git I would create another branch and squash all changesets outside of the index, then I w开发者_如何学运维ould add the specific files to the index and commit. After that, I could merge this temporary branch with master so master has a clean commit with only the non-destructive change. I don't know how to do this with Mercurial.


You can use hg cat to grab the contents of a file as it exists on any particular branch, and replace the working copy version with that.

This isn't technically a merge, but since you're replacing whole files you shouldn't have too much of a bad time merging things later:

for example, to grab myfile.c form branch somefeature, and replace the working copy version, do:

hg cat path/to/myfile.c -r somefeature > path/to/myfile.c

note that this completely replaces the working copy file so make sure you have no outstanding changes first


I think mercurialqueues is what you want. With mq you can turn any changeset into a patch and any patch into a changeset. So taking a changeset converting it to a patch deleting the chunks out of the patch that you don't want and then applying it to whatever branch you want. This is a fairly complex operation though and requires a certain amount of discipline on your part. So I would try to nail down your workflow on a test repo before trying it on code you care about.


As far as I know, Mercurial doesnt any have tools to split changesets. If youre lucky, all the changes you want are in separate changesets and then you can use the TransplantExtension. I think it can be compared to Git's cherry-pick but I havent used git much.

You can also use hg diff to manually commit the changes to a certain file to a new branch. Use the rev range to mark your entire source branch:

hg diff myfile -r startrevision:endrevision

The output can be treated as a patch. Do this for each file you want and commit them and then merge. Skipping the destructive changes. You can also, of course, do this multiple times of a destructive change is in the middle of a revision range.

Having said that what youre trying to do isnt something mercurial was built for. That hardcore history editing is more Git's area (note that its just my opinion). Keep your stable changes and destructive changes in separate changesets (and maybe even in separate branches). I use transplant, rebase and strip to move changes around. When its all done, they are merged and properly pushed.

Oh, and check MercurialQueues. I havent used it myself but Ive seen it do some crazy stuff. Maybe its capable of doing something along the lines of what you want.

0

精彩评论

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