What to do when hard link is lost because of my text editor

TheDeepNate

So, I have a file, for this instance we shall call it $HOME/Documents/hello.txt. I will write some text inside it:

Hello, welcome to my text file

And I will hard-link this file here: $HOME/Documents/Backup/hello.txt.

Okay, great, this is now hard-linked. If I write to the original file, the hard-link will be updated:

echo "Hello again" >> $HOME/Documents/hello.txt
cat $HOME/Documents/hello.txt
Hello, welcome to my text file
Hello again
cat $HOME/Documents/Backup/hello.txt
Hello, welcome to my text file
Hello again

Now, my problem is, whenever I open either file (either of the hard-linked counterparts) with lots of programs that create temporary files, it loses its link relationship, and neither file will update the other anymore.

So, what can I do in this situation?

Note: I can not use symlinks in this situation, because I am using my hard link for Github to backup some files, and Git doesn't follow symlinks.

Jürgen

As mosvy already said in this comment, most editors do the edits in a copy of the original file which they replace (delete) later. While this increases security, it breaks hard links.

However, some editors like for example GNU Emacs can be configured to perform file edits in place, which means that they directly alter the original file, like you did in the shell. For example this Question and the corresponding answer discuss exactly your problem with respect to Gnu Emacs. So your editor's configuration would be the first point to look at.

Since you need the hard link only (?) for Git—unfortunately you are not very detailed on your workflow—, it is likely that you can use Git hooks to reestablish a correct hard link immediately before committing what you subsequently like to push to GitHub: The pre-commit hook seems to be a promising candidate for that. See man page githooks(5) for details.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Oracle Apex - Link text is lost when saving

What happens when you delete a hard link?

What does "link with editor" feature do in Eclipse?

What do link editor (LD) params mean?

How do I find out what my default terminal text editor is?

What is a hard link in Linux?

Hard link cells in script editor for Google Spreadsheet

setuid (and other) permissions lost when copying / elsewhere - what to do?

My hard drive seems to be overheating... what should I do?

What to do if my hard disk has bad sectors?

How do I embed code through my text editor?

Why does my text editor suggest "XXX" when editing html

What is the difference between a symbolic link and a hard link?

What is the difference between a hard link and a symbolic link?

How do I change what my Assistant Editor view is in Xcode?

What to do when one key needs to be pressed hard to register?

What should I do when hard "disk failure is imminent"?

What should I do when my antivirus is not letting me access my router's control panel (because off a cross-origin script)?

Why are hard links are not updated when modified with an editor

what can I do to fix my jQuery without any hard-coding in my HTML?

Why does the position of my text change when I make it a link?

What do you think of my table in mysql workbench ? Link table?

What's the cause of this link error when I try to link my executable to my library by name?

What to do when my Mac is frozen?

What is the difference between a hard link and a file?

How do I make Sublime Text 3 my default text editor on Windows 10?

I am lost and do not know what to do

Lost keystore password, what are my options?

What text editor is git using?