如何在不替换原始文件的情况下对分散文件进行版本控制?
我想在不同的目录中保留几个文件,并使用 git 进行版本控制。有些在我的主目录中,有些在 /etc
中,我显然不想让 root 成为 git 存储库。
这可以通过将所有文件放在一个文件夹中并将链接放在其预期位置来实现,例如 /etc/resolv.conf -> /home/tim/my-repo/etc-resolv.conf
,但没有必要为了适应版本控制软件而对我的系统进行太大的改变。
如何在不用链接替换原始文件的情况下对文件进行版本控制?
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 originals with links?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
听起来您真正需要的是一个好的备份解决方案。 Git 做得不好的事情之一是文件属性,如所有者、组、权限、SELinux 安全上下文。当您开始使用 Git 管理系统文件时,事情会变得非常糟糕。
我会保持简单并使用常见的备份实用程序,例如 rsync、cpio、tar 和 cron 以及合适的备份政策。
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
andcron
with a suitable backup policy.git 的整个思想基于这样的假设:您有一个想要受版本控制的目录。
一种可能的解决方案是将整个文件系统置于 git 下,但使用 .gitignore 排除任何内容,但有一些例外。
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.
将每个目录设为 git 存储库,然后通过不同的分支名称推送到公共存储库。
希望这有帮助。
make each directory a git repo then push via a different branch names to a common repo.
hope this helps.
Git 最适合在一些公共项目目录中管理源代码,而不是在不同目录中管理单个文件。
可能可以通过一些编码来伪造一些东西,例如读取随后提交的文件列表的提交钩子,但是让 git “通知”对这些远程文件的更改将很棘手;-)
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 ;-)
刚刚遇到这个问题,因为我也有同样的问题。我想对一些(但不是所有)系统配置文件和各个不同目录中的一些脚本进行版本控制。
我发现两个 git 功能可以在这里提供帮助:
您可以用一个文件替换 .git 目录,指向真正的 git 目录。这样,如果您将 .git 文件放在 / 中,您可以将 .git 目录放在选定的位置,并且仍然拥有全局 git。
.git 文件的格式为:
第二个是简单的全局排除。只需将全局通配符 (*) 添加到文件 /info/exclude 中即可。这默认排除所有文件。要跟踪文件,您必须使用“git add -f”显式包含它。
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:
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'.