How do you disable mercurial from leaving .orig files after a merge?
Asked Answered
K

5

34

After updating TortoiseHg+Mercurial a while back I am starting to get .orig files after merges. I have looked at the solutions for removing/purging them but I am looking for a way to disable the files from being left behind. After doing merges fine without these files appearing I was wondering if this was something new that could be turned back off.

Kistna answered 15/9, 2011 at 10:21 Comment(4)
Which versions of Mercurial/TortoiseHg did you upgrade from and to?Sprage
The version I have now is tortoisehg-2.1.2 hg-1.9.1, not sure what version it was before but might have been 2.0.4Kistna
Found old installer and it was 2.0.4, uninstalled current and re-installed 2.0.4. Did a merge and used KDiff3 (no changes) and did get an .orig file. Not sure why I am getting these files now as I did test merging on this old version.Kistna
It may be useful to put .orig files in your .hgignore file. This doesn't totally solve the problem but it does help to get them out of the way for a lot of operations.Mimicry
M
12

Update:

According to the Mercurial config documentation the defaults section is deprecated. The Mercurial wiki is also particularly critical of their use. The recommended replacement is to create a command alias (while not shadowing built in commands) that provides the functionality you are looking for. Here's what I've switched to in my config.

[alias]
undo = revert --no-backup

Original:

I stumbled across this while experiencing the exact same problem. I had been just dealing with it and deleting the .orig files, since I never seem to need them. The best recommendation I've found was on StackOverflow and suggests using the defaults section of your hgrc file. To address this specifically, add the following section:

[defaults]
revert = --no-backup

Here's where I read about this.

Mysterious answered 11/9, 2013 at 19:16 Comment(10)
I have switched to GIT now due to other issues I had (including this one) but seeing as the answer is accepted on very similar answer I'll mark this as the answer. Thanks.Kistna
@Darren: Because this was an accepted answer, I wasted my time trying it, only to discover it requires an extension to be enabled. And, according to mercurial.selenic.com/wiki/Defaults, that extension is deprecated.Noachian
@Noachian I wasted a lot of time trying to solve this too, that's why I switched. It works on the version I downloaded in 2011. You can post an answer for the current version of mercurial then mark the new answer.Kistna
@StriplingWarrior: What extension needs to be enabled for this to work? I just tried it with Mercurial 2.8 (installed via TortoiseHg 2.10) and got the same result.Mysterious
@xiterion: The "Defaults" extension that I posted a link to. TortoiseHg kept crashing when I tried to add the code listed here. That site heavily recommends using aliases instead of defaults.Noachian
Updated so the answer isn't so unequivocally recommending using a deprecated feature. Let me know if I missed anything important.Mysterious
1) What does revert have to do with merging? 2) Aliases won't work because the command is not for me but for NetBeans' Mercurial plug-in.Liz
@MarkJeronimus I don't remember now what the relationship between revert and merge was, aside from my particular problem involved revert creating .orig files. I tried to recreate the specific behavior of merges creating .orig files on the latest Mercurial (3.1.1) and could not, and I don't believe I have anything in my configuration that prevents it from happening any more. Perhaps you can update the Mercurial install the NetBeans plug-in depends on and get rid of that particular annoyance.Mysterious
+1 for your update. I have edited your answer to put it at the top because it is more valuable info than the deprecated stuff. Feel free to "undo" if you don't like it.Vendace
I agree with @MarkJeronimus, although this is useful info it does not answer the question. You could ask + answer a separate question about this with revert.Mimicry
S
8

Personally I will add *.orig files to the hg ignore list, and from time to time do a

rm **/*.orig

Alternatively you can use Hg Purge extension

Shawndashawnee answered 5/1, 2012 at 7:36 Comment(2)
This is probably a better command if you want to remove all *.orig files recursively in a shell such as bash: (cd `hg root` && find . -type f -name "*.orig" | xargs rm)Flori
...or just "find . -type f -name "*.orig" -delete"! :)Blowgun
S
4

The following seems to be enough to convince hg not to write these files:

# ~/.hgrc
[ui]
origbackuppath = /tmp/hg-trash
Sagesagebrush answered 24/5, 2018 at 12:16 Comment(2)
/dev/null doesn't work for me. A good directory choice is /home/yourUserName/.local/share/Trash/files. This way, you keep the safety against accidental revert without polluting your repo with .orig files.Jeaninejeanlouis
Thanks, I did notice that some commands raised errors with /dev/null. I have updated the answer to use a different directory.Sagesagebrush
T
1

I got it working in SourceTree by disabling backups in application.

enter image description here

Terce answered 30/9, 2016 at 12:10 Comment(0)
P
-4

It is KDiff3 that is leaving the .orig files, not TortoiseHg.
This is how to disable this setting:

Settings - Configure KDiff3 - Tab Directory
Last CheckBox: "Backup files (.orig)"

Phrenic answered 15/9, 2011 at 19:28 Comment(4)
I've tried CodeCompare and P4Merge and they both leave files. Not tried KDiff3 but might do if it can deal with the files. Will have try it out.Kistna
Tried this option and still leaves the file. Looks like it's Mercurial leaves this file after a merge.Kistna
Darren is right: Mercurial adds this file even if you don't use a third-party merge tool.Noachian
KDiff3 does have a "Backup files (.orig)" option.Destinee

© 2022 - 2024 — McMap. All rights reserved.