Bloody emacs breaks hard links by default!
I switched to using .emacs.d/init.el
as my init file a while ago, since I often edit it at the same time as other .el files I use for keeping functions I write. But I like having .emacs
, so not long ago I decided to just hard link them. A few days ago, I was having unaccountable trouble getting a customization to work and I discovered the .emacs
file had been replaced with a copy, so it hadn't changed. I thought "Huh, how did that happen?", deleted it, relinked it... Then today I'm having the same problem again... I can't work out why my C-h C-m
keybinding isn't working (try replacing C-m
, try changing the value in help-map
directly...). I check .emacs
and sure sure enough, it's happened again.
It turns out that emacs replaces
hardlinked files by default. I really don't understand why they'd do this*. It's good to have the option, but this is crazy as a default. If I hardlink a file and edit it, I expect to be editing the hardlinked file. I don't expect to have the link broken and an identically named file replace the one I opened!! WTF emacs?
At least I found out now
. I've also put the rest of my dotfiles hardlinked in a dotfiles directory for easy backups, and I realize now they're all going to be the old versions. I'm glad I didn't discover that in the future after reformatting my hard drive or something.
Btw, the command to change this is
Code: Select all
(setq backup-by-copying-when-linked t)
(or set 'backup-by-copying
if you prefer)* the name of the variable controlling the behaviour, 'backup-by-copying-when-linked, gives a clue about what's going on. The file is renamed into the backup and the new data is saved as a new file of the old name. So the behaviour is essentially a side effect of the backup mechanism. But it's not like they haven't noticed the implication for hard links in all these years (they've made a variable specifically for the case of linked files!) So keeping the defaults is still a deliberate decision.