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.
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.
Comments