I have a patch file here in unified diff format I'd like to import. But when I do it in the workbench via Repository -> Import, it just closes the window and it seems that nothing happened. What could go wrong here?
Are you importing the patch on top of the correct previous revision? Patch contains only the changeset and it to work properly you need all its previous changesets applied on your branch before hand.
Related
I am trying to use patches (to revive a corrupted repository) for the first time in my life. So I am not very well familiar with the concept, though I've read a bit. I am using TortoiseHg. I have created a patch (as a file), switched to another repository, and am trying to import it. I've asked THg to import it to Repository (other options are Shelf and Working Directory). When I click Import, THg says that the patch was imported to a working directory and the Console reads:
% hg import --verbose --"PATH\1059.patch"
applying PATH\1059.patch
applied to working directory
[command completed successfully DATE]
and I don't see any changes in the history window (no revision 1059). I wonder what I should do now or what I am doing wrong.
I am on Windows 10, TortoiseHg 4.9 with Mercurial 4.9.
When something is modified in your working directory by any means, it does not automatically affect anything in your repository. You have to manually commit such a change.
For the command line hg patch I think the default is to commit automatically. It may be that THG is using the --no-commit option. You could inspect this in the THG output / log window.
For the command line, there is also this note in the help import ...
first applies changes to the working directory (unless --bypass is
specified), import will abort if there are outstanding changes.
The THG Import window looks like this:
According to the docs
You have the choice of importing directly into the repository, the
working folder, a shelf file, or your patch queue.
I think if you inspect the "patches will be imported to" dropdown, it may be set to "working directory" or similar. If you change it to "Repository" I think it will commit for you.
Unless a better answer is provided, I have to assume that this behaviour is due to the corrupted repository: it is not observed when doing exactly the same with a non-corrupted repository.
I have a situation where I renamed a few files I was tracking in a mercurial repo without using hg rename command (just doing it via the file system).
This occured several revisions ago
Now I want to return to a revision prior to the file renames, fix a bug, and then rebuild that old revision
problem i have is that i am getting error messages along the lines of:
remote changed file.txt which local deleted
use (c)hanged version or leave (d)eleted?
Is there a way I can fix the mistake I made when renaming the files all those revisions ago?
Depends on whether you committed the deletion of the files, but I assume you didn't and it doesn't seem so.
Then you can simply revert them in order to restore them to your working dir: hg revert file.txt. After that you can update to the previous revision without this question popping up. Alternatively just update to the previous revision you want to fix and accept the (c)changed version from remote.
If you want the rename to be permanent and also tracked by the repository, then commit that rename. Use hg addremove, possibly check with --dry-run first what it does so that no unwanted changes are added and commit the renaming of the files. Then go and update to the old revision and do whatever changes you want to commit there.
I don't want this file to be removed from other developer's machines, but I don't want it tracked anymore either. It is basically a setting file, that shouldn't have been checked in in the first place.
I think I have to tell the other developers to back up this file. Then I can do a remove, and add it to the .hgignore. Then they have to put the file back into their working directory.
It seems like hg forget would only work for my machine, and then next time another developer does a pull it would wipe out their file.
Any tips?
They don't need to back it up. It's backed up in the repository. You might want to get them to commit their latest version before they pull from you so they don't lose their latest changes. When they lose their file they can just do hg log <file> and then hg revert <latest revision - 1> <file> to get it back.
It seems like hg forget would only work for my machine, and then next time another developer does a pull it would wipe out their file.
Yes, non-versioned file will be saved (some time) only in your WC
If you don't want kill file and just ignore, you can
use -X filename on commit by hand (or write in aliases section)
install (on all workplaces) Exclude Extension (semi-automated solution from p.1)
I have successfully imported patches without having conflicting changes. But when I try to import patch with conflicting changes it throws an error saying "Hunk #1 FAILED at 11.. ". There is no option to merge changes. Is there any other way to accomplish this?
Failed hunks have to be fixed manually. There should be a *.rej file with the rejected hunk from the patch. You will have to apply it manually.
see: https://www.mercurial-scm.org/wiki/HandlingRejects
Manual resolution
The latest versions of TortoiseHg 2.1 have tools for helping you resolve rejected chunks from patches. When you apply a patch and it has rejections, for each file with rejections it asks if you want to resolve rejected chunks. If you click Yes, it shows you a screen with the content of the file (with successful chunks applied) as well as each chunk that was rejected, to allow you to manually do the changes a little easier and mark each as resolved.
Achieving 3-Way Merge
The way that I sometimes handle large rejections is to rebase the patch. In TortoiseHg 1.x I could select one node, right-click on another and actually rebase patches. In TortoiseHg 2.x they have not yet added that back in, but the workaround isn't so bad. You can still rebase patches on the commandline using hg rebase. In either case, you need the mq and rebase extensions enabled (and you probably already have the former enabled). This answer is not a place for teaching how to use mq or rebase (there are plenty of other answers and articles that do that), so I will be assuming some familiarity with them.
In both, you will need to apply the patch to the revision on which it was based (or to one where it applies cleanly or close to clean).
Commandline:
Run hg rebase -s patchRev -d tip. Along with whatever other switches you want on the rebase command.
This will bring up your 3-way merge tool to resolve conflicts, for each file.
Run hg qrefresh to make sure the merge results are updated into the patch.
TortoiseHg UI
Finish the patch as a normal changeset.
Rebase that changeset onto the tip:
Update to the tip. This is important as it used to set the target of the rebase operation.
Right-click on the temporary changeset and select Rebase to bring up the Rebase dialog.
Review that source and destination are correct, and click Continue. If there are merge conflicts, click on the resolved link that appears to open the Resolve dialog.
Click Mercurial Resolve to let Mercurial try to automatically resolve some conflicts.
For anything else that remains use Tool Resolve to bring up 3-way merge for selected files.
Once all are resolved, click Close on the Resolve dialog.
Click Continue and then Close on the Rebase dialog.
Right-click on the temporary changeset now at the tip and go to Modify History > Import to MQ. Now it is a patch again.
I prefer the latter method for the more troublesome instances because it by default prevents Mercurial from automatically resolving conflicts. It allows me to choose the order in which I resolve files and how I resolve them, showing the status of my progress with each step.
I've just recently moved a lot of my Views and Controllers into more appropriate locations and am now wanting to pull down recent changes from our central repo.
I've done a hg pull which worked fine and asked me to do a hg update to bring the changes down locally. This in turn informed me that I needed to do a hg merge however when I try this, I get a message stating that
abort: outstanding uncommitted changes
When I check this using hg status I see in the list all of the files that I've moved (so they're now deleted from their old location).
How do I tell Mercurial that I've removed these files? Do I have to go through each one of them and manually do a remove? Is this something that's possible using only the command line rather than doing it with a GUI tool?
From the command line to automatically hg rm the files you've removed you'd:
hg addremove
It's likely your GUI (you didn't say which you use) exposes that functionality too.
However, that's not what's causing your message. You have some already made local changes that mercurial does know about (unlike the removed files which it doesn't know about until you tell it), and you need a hg commit before you can merge.