I'm trying to merge the latest revision of our main branch into a much older branch. There's only two files that have conflicts, but the conflicts are complicated and I'd like to manually copy the changes from the more recent revision and fix some things. There's been a tonne of commits since the last commit into the old branch and I don't know when those two files were changed.
Using TortoiseHg, how can I find the latest revision on any branch where a particular file was changed?
From Windows Explorer, right click on the file whose history you are interested in.
In the TortoiseHG menu, select "Revision History":
This will bring up a window showing only the changesets which have modified that file (in any branch). It should also show history across tracked file renames (if the hg log "follow" option is enabled in hgrc), copies, and moves.
You can also get to the same thing from within the THG Workbench application, from the lower files list, where it is called "File History":
Either will bring you to:
Furthermore, command line equivalents of this screen would be to use hg log file and hg annotate file.
Related
I committed a changeset which is now in the "draft" Phase. It is the latest (local) revision. I want to remove that changeset and move all the changes back to the working directory. That means I want the opposite of committing it (which is working directory -> revision).
I tried the strip command with both keep and without. In both cases my changeset is removed but the changes are gone and the working directory is still empty. Then I need to unbundle the backup and pull it, at which point I'm exactly where I started with the local changeset in the history.
How do I move the changes from the committed changeset to the working directory? Maybe backout?
I'm using TortoiseHg but can also use the console there.
This doesn't directly answer the issue about the behavior of strip, but another way to do this in THG would be:
Shelve anything of value in your working folder
Update to the last-desired revision (the one before the revision you mean to undo)
Select the revision you want to undo and click "Revert All Files..."
Let it revert. The working folder will now match the revision you want to undo.
Strip (without "keep") the unwanted revision. Or even just leave it there and ignore it.
Looks like I managed to solve it, though I don't really understand how it works.
Following this answer I updated to my revision, switch to Ammend which showed the patch changes in the working directory as well as the revision, then strip with keep removed the revision, only the working directory now contains the files because of Ammend.
I am using TortoiseHg and I have some changesets in draft mode and now due to some reasons I am in a situation to use a different machine.
So, is there any way to like take a backup and restore my changesets on a new machine?
Since I'm not sure about fetching the draft mode changsets on a different machine.
If you already committed, but not pushed the changesets, you can just copy the .hg direcotry to the other machine. If you have uncommitted changes, you have to copy the entire directory where your repository and .hg directory is in.
And no, you can't fetch draft mode changes on another machine. They are available once you pushed (status "public").
You can do this regardless of the phase (public/draft/secret) of the changeset - I do it all the time at my work using patches.
For this you will need the "mq" extension (installed but not enabled by default) turned on from your settings. (actually, you can do this without mq)
Take the following steps, working your way from the first draft changeset (i.e. the one whose parent is public) to the last draft changeset (i.e. the one which is at the head):
Right click on a single changeset in the source repository and select Export/Copy patch, the output of which you can paste into a text file. Repeat this n times to get the patches you want to copy.
Transfer those text files to the other machine, then select Repository/Import on the target repository then import the changeset. Repeat this (in the order the changesets were exported) to recreate the same history as on the source repository.
I use Tortoise Mercurial tool to manage my mercurial repository.
And I have a separate .diff file containin0g changes to a file in my repository.
Is there any way how to use that diff to update my file ?
thank you
Most Linux repositories comes with the patch program. You can then execute:
patch original.data difference.diff
Patch will modify the original.data file in such a way that if one would calculate the diff between the final and original state, one gets the same difference.diff again.
.diff files are in general not visible in a subversioning respository. They are stored internally to hide the several commits from the user. Diffs however can be usefull to analyze the difference between two commits. Say for instance somebody worked on your project and made a lot of commits, you might want to inspect what that person actually did without having to read the reports of all commits (since some changes can be undone in the next commit)
I have two machines, window 7 with TortoiseHG 2.6 and Linux with TortoiseHG 1.5. I use bitbucket as a website to hold my centralized repository. The window machine associates with bitbucket user account, Cassie-win and the linux machine associates with bitbucket user account, Cassie-linux. Here are the steps I have performed.
created a empty centralized repository at butbucket Cassie-linux account
create two files locally, file1.txt and file2.txt on linux machines and push them to the Cassie-linux account.
Add user Cassie-win to the repository
Clone the repository to the window machine, make changes on file2.txt there and push it back to the centralized repository.
Meanwhile, also make some changes on the file2.txt which is on the linux machine and commit locally
Then I pull changes from the centralized repository at Cassie-linux account to my local linux machine. Now my linux local repository has two heads because of different contents in file2.txt and I would like to merge them together.
I used the "merge with" tool of TortoiseHG on my linux machine to merge these two heads. However, it kept failing to do so. I tried like a hundreds times and didn't know where I got it wrong. Both file1 and file2 are test files that have only three lines. I also used a command "hg resolve file2.txt" to check the error. However, it only showed that mergeing fails and didn't shown much information. Does anyone know how to use TortoiseHG merge tool to merge two heads ? And what could be the problem to stop TortoiseHG merging two heads ?
I embedded the screenshot which I took on the Linux machine which has TortoiseHg 1.5.
I right clicked the "from Cassie-win account" and it has "merge with" option. Then, I clicked the "merge" option with "merge" tool but it failed with error messages as below.
Thank you very much,
By "merge with" in TortoiseHg, do you mean you tried "Merge with Local" from the context menu of one head after updating your working directory to the other head? If so, you should have seen a wizard taking you through the steps of a merge. TortoiseHg will expect you to intervene if it cannot automatically merge the two heads. Once it asks you to do that, you have a few options including "Mercurial Resolve" and "Tool Resolve."
If you could post more details about the errors you see when the merge "fails," we might be able to be more helpful.
First things first: A merge just creates a new file version. You must commit it before it can be seen or pushed to your other repo clones.
Now, if you're doing a merge and the same line, or adjacent lines, have been modified in both merge parents, the automatic merge won't succeed and you'll be asked to choose what to do at each conflict point. Kdiff3, the tool that TortoiseHG uses for merging the files on Windows is not terribly intuitive, so here's an overview:
If there are multiple files to merge, you'll see a directory control. Navigate to one of the files and open it so you see two file versions side by side.
Depending on the circumstances, you may now have to activate "Merge this file" (in the Merge menu and on the toolbar), which will show you a third version of the file (the merge result) below the other two.
You can now navigate from change to change, and click on the A and B buttons to select which change to use. Note that the buttons are toggles, and it is possible to activate both together (to import both versions to the merge). Note also that you'll also see diffs that could be automatically merged. In general you can leave them alone (there are navigation buttons that go directly to the next unresolved diff).
Once you've figured out how to work all this and chosen a version for each diff, you'll be able to save and go on to the next file. When you're done, your merge is ready to commit.
Edit:
So you need to do this on the Linux side, and you've got no Kdiff3. Ok, then do it the old-fashioned way: Using the commandline and a regular editor.
When a merge fails, the conflicted file turns into a context diff that includes both revisions. Open it with your favorite editor, look at it carefully and clean up each context-diff region (you'll know them when you see them) until you have a clean, usable file just as you want it to be.
Exit, drop to the command line and type hg resolve -m file2.txt. This removes the file from the list of conflicts.
When you've done this with all conflicted files (you can list them with hg resolve -l) you'll be allowed to commit, and your troubles are over.
PS. If you don't like the merge tools you've got, consider installing kdiff3 (it's available for linux, but no idea how well it works), or p4merge as #LazyBadger suggests.
Side notes
You can exchange data between your hosts without "Bitbucket-in-the-middle": just hg serve on both hosts and hg pull <PARTY> on opposite side
You could use single BB-account from both our hosts (less management on BB-side) and differentiate source of every changeset in Bitbucket interface only by usernames in changesets
To the question of merges
When (in any SCM) you try to merge two diverged lines of coding, there are two possible cases
Independent changes are not overlapped and can be combined into common descendant without user's intervention. If this case merge "just happens"
Changes are intersected and some strings are in conflicted state: i.e we have two different changes for some old data. It this case user's choice is needed and SCM or store merge-result with conflicted parts marked (and note merge as unsucceful and unfinished before appropriate user-action) or run user-defined merge-resolver (read "Visual Merge Tools")
In your situation, obviously, he have second case: some strings from 3 in merge-sources was in conflict and you haven't configured in TortoiseHG Diff/Merge tools (TortoiseHG - Global Setting - TortoiseHG)
Have and add these tools will be best choice for future. Now you have by hand edit file-in-conflict and select correct data in conflicted lines, mark conflict as resolved (check TortoiseHG context menu of file), remove temp-files and, at last, commit merge
Suppose the repository has 20 revisions. The current revision on the record is revision 10, while the actual local files are based on the latest revision 20. I do not want to branch from revision 10. I want to continue the revision 20.
Currently what I'm doing is to copy all the files out of the revision directory, run hg update -C (which updates the revision number), remove all the files in the repository directory, copy all the files back, then commit. You can tell this is annoying and time wasteful. Is there a way to only update the revision number, but not modify any local file?
Thanks in advance.
EDIT: there are many use cases (I mainly use TortoiseHg).
1) I mistakenly choose "No" when prompted to remove files from repository during a commit. I can use the strip from mq to remove the revision, but that will revert all commited files. Instead, I want to "re-parent" to the previous revision, commit again, then strip the unwanted revision. This may happen to anybody anytime, not just me, not just once.
2) I had a development machine A. I started the project on it, and switch to machine B after several months. The code on A becomes old, and the code on B has uncommited changed. If I want to continue development on A, I need to copy the code to A via Flash or network, etc. Now I want to commit on A without branching (because the code on A is actually based on the current tip). This happens maybe less frequently, but still not "once" problem, and more possibly when involved in a big project.
3) The repository has 2 branches C and D. There are roughly 2000 files. The current tip is in C. I want to overwrite some files in D with the same-named files in C (because C is more implemented) while preserving other files unchanged, then make the new tip in D. I have several options. I could update to D, compare the last revision of D with the current tip, make change and commit. The update would take some time, and the difficulty of comparison heavily relies on the comparison tool. I could also compare first, make change, backup the entire directory, update to D, then restore the entire directory. This is even more cumbersome. But if I could "re-parent" to D, I just need to make change and commit. This does not rely on comparison tool because the commit window in TortoiseHg has diff list.
There could be more use cases if you want to think. I hope Mercurial provides such "re-parent" feature (supposedly a new option for hg update), or at least convenient alternative.
You might find this article useful. The original link no longer exists, so it now references the Internet Archive's copy:
https://web.archive.org/web/20170805042314/http://hgtip.com/tips/advanced/2010-04-23-debug-command-tricks
In particular, to "reparent" your current working directory, issue:
hg debugsetparent 20
hg debugrebuildstate
You can use hg debugsetparents to set the parent revision of your working copy.