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.

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
  • Which versions of Mercurial/TortoiseHg did you upgrade from and to? – Luke Girvin Sep 15 '11 at 10:31
  • 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.4 –  Sep 19 '11 at 12:06
  • 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. –  Sep 19 '11 at 12:27
  • 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. – StayOnTarget May 16 '19 at 11:59

5 Answers5

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
xiterion
  • 190
  • 1
  • 7
  • 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. –  Sep 12 '13 at 08:59
  • @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 http://mercurial.selenic.com/wiki/Defaults, that extension is deprecated. – StriplingWarrior Nov 05 '13 at 00:11
  • 1
    @StriplingWarrior 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. –  Nov 06 '13 at 13:56
  • @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. – xiterion Nov 21 '13 at 22:09
  • @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. – StriplingWarrior Nov 21 '13 at 22:38
  • Updated so the answer isn't so unequivocally recommending using a deprecated feature. Let me know if I missed anything important. – xiterion Nov 22 '13 at 21:22
  • 1
    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. – Mark Jeronimus Sep 19 '14 at 13:29
  • @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. – xiterion Sep 21 '14 at 17:05
  • +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. – Felix Dombek Oct 16 '14 at 15:45
  • 1
    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. – StayOnTarget May 16 '19 at 11:55
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

Clonkex
  • 3,373
  • 7
  • 38
  • 55
simonecampora
  • 397
  • 2
  • 8
  • 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)` – arr_sea Apr 12 '13 at 19:33
  • 3
    ...or just "find . -type f -name "*.orig" -delete"! :) – folkol Oct 13 '15 at 12:46
4

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

# ~/.hgrc
[ui]
origbackuppath = /tmp/hg-trash
Kevin Cox
  • 3,080
  • 1
  • 32
  • 32
  • 3
    `/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. – Kevin Jul 27 '18 at 15:14
  • 2
    Thanks, I did notice that some commands raised errors with `/dev/null`. I have updated the answer to use a different directory. – Kevin Cox Jul 28 '18 at 07:53
1

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

enter image description here

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Jozef Vrana
  • 309
  • 1
  • 5
  • 14
-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)"

jan
  • 1,581
  • 2
  • 19
  • 34