Reputation: 281
I'm using some proprietary software that is configured with a dozen or so text files stored in a specific directory. The software is relatively well-behaved in dealing with user modifications, it keeps modifications it makes to the files while running in a separate section of each file. But I'd like to track the changes, both ones I make manually and ones made by the software.
Ordinarily, this would be a great use case for Git: make the config directory a Git repo, and it'll identify the changes no matter how they got made. I can look at the diffs, commit changes, experiment with a bunch of changes at once with a branch, roll back, and even use git bisect
if something goes awry. I can push the repo up to GitHub on one machine and pull it back down to others, and changes made on one can be merged with changes made on another.
The problem is that one of these files include the username. So on one site the file is trey.conf
, on another it's treyharris.conf
. I need Git to recognize these as the same file.
A symbolic link seems like the obvious choice: rename the file to a static name like user.conf
and symlink the other names to that file. And that works, for the software's reading the config and for manual configuration changes. Unfortunately, the software doesn't respect the symlink when writing out changes, and replaces the trey(harris)?[.]conf
symlink with a plain file.
So far, I've dealt with this just by coming behind every time I want to commit and fixing the situation by moving the username-specific file back to user.conf
and restoring the symlink. But this is getting more and more annoying as time goes on.
Is there some Git magic I can use to rectify this? I thought maybe filters were the way to go, smudging into ${USER}.conf
and cleaning back into user.conf
, but I can't figure out how to make that work correctly.
Upvotes: 2
Views: 817
Reputation: 164679
Instead of a symlink, try a hard link.
A symlink can be thought of as a special file which contains another file name to use instead. It can be overwritten by a real file.
A hard link is where multiple file names all point to the same underlying data. A hard link looks just like a normal file because it is a normal file; all normal files are hard links.
Try ln user.conf trey.conf
and ln user.conf treyharris.conf
and see what happens.
Otherwise, you've run into the general problem of trying to use version control as a build and release management tool. You might be able to hack things to work, but really what you need are build and release scripts.
Upvotes: 1
Reputation: 601489
Git can detect renames itself. Just leave the name of the file as it is, don't bother with the symlinking. Run git add -A .
to add all changes to the index after external changes have been made. git status
should now show a "renamed: treyharris.conf -> trey.conf" if the files are still similar enough. Some git commands need special options to enable rename detection, e.g. git log
and git diff
both require the -M
flag to detect renames.
Upvotes: 1