How to version-control spread-out files without replacing the originals?
I want to keep a couple of files in different directories under version control with git. Some are in my home directory and some are in /etc
, and I obviously don't want to make the root a git repository.
This could be achieved by putting all files in one folder and links in their expected locations, e.g. /etc/resolv.conf -> /home/tim/my-repo/etc-resolv.conf
, but it shouldn't be necessary to change my system that much just to accommodate for the version control software.
How to version-control the files without replacing the orig开发者_StackOverflowinals with links?
It sounds like what you really need is a good backup solution. One of the things Git will not do well is file attributes like owner, group, permissions, SELinux security contexts. Things can get really hosed up when you start managing system files with Git.
I would keep things simple and use common backup utilities like rsync
, cpio
, tar
and cron
with a suitable backup policy.
The whole idea of git is based on the assumption that you have one directory that you want under version control.
One possible solution would be to have the whole file system under git, but use .gitignore
to exclude anything, with some exceptions.
I don't think there is a viable alternative to links.
make each directory a git repo then push via a different branch names to a common repo.
hope this helps.
Git is best suited to source code management within some common project directory, rather than individual files in disparate directories.
It may be possible to fudge something with a bit of coding e.g. a commit hook that reads a list of files that it then committed, but making git 'notice' changes to those distant files would be tricky ;-)
Just came across this question because I have the same problem. I'd like to version-control some, but not all system configuration files and some scripts in various disparate directories.
I found two git features who can help here:
You can replace the .git directory with a file, pointing to the real git directory. This way you can place your .git directory in a chosen place and still have a global git, if you place the .git file in /.
The format of the .git file is:
gitdir: /path/to/your/.git
The second is a simple global exclude. Just add a global wildcard (*) to the file /info/exclude. This excludes all files per default. To track a file you have to include it explicitly with 'git add -f'.
精彩评论