如何在 git 中共享配置文件?

发布于 2024-08-21 23:35:00 字数 360 浏览 8 评论 0原文

我有想要在所有存储库中传播的编辑器设置。如果用户定义了自己的设置,那么它当然应该删除存储库选择。

我想这样做,因为我有一个班级,每个学生都克隆该存储库。通常他们会忘记设置 core.editor 设置并最终乱搞 vi,通常会导致仓库崩溃,就像他们拥有了被诅咒的魔法力量一样。

由于它适用于我的主目录,我尝试在我的存储库目录中使用 .gitconfig,就像我设置 .gitignore 一样,但它似乎不起作用。

编辑:

  • --global 确实允许用户设置其首选项来覆盖存储库,但它不允许他在克隆存储库时获取存储库配置。
  • .git/config 不在克隆的存储库之间共享

I have editor settings that I want to spread in all repositories. If the user defines its own settings, it should erase the repository choices of course.

I want to do that because I have a class and every student clone the repo. Usually they forget to set the core.editor setting and ends up messing around with vi, usually crashing the repo just like if they have cursed magical power.

As it worked for my HOME dir, I tried to use a .gitconfig in my repo dir, like I would set a .gitignore, but it doesn't seem to work.

EDIT :

  • --global DOES let the user set its preference to override the repo, but it DOES'T allow him to fetch the repos config while cloning it.
  • .git/config is not shared among cloned repo

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

等待我真够勒 2024-08-28 23:35:00

使用 rsync 或 tar/untar 分发您的存储库,而不是使用“git clone”,正如您所见,它不会复制存储库特殊文件。

Distribute your repo using rsync or tar/untar, rather than using "git clone", which as you have seen, does not copy repo-special files.

生死何惧 2024-08-28 23:35:00

我通过将配置文件移至工作目录以对其进行版本控制来实现此目的。

然后,您可以要求其他人建立指向配置的链接:

$ rm .git/config
$ cd .git
$ ln -s ../config config

然后您可以将其写入脚本或一行中,以便他们复制和粘贴。

I do this by moving the config file up to the working dir to get it versioned.

Then you could ask the other person to make a link to the config:

$ rm .git/config
$ cd .git
$ ln -s ../config config

You could then write this in a script or in one line to let them copy and paste.

↙温凉少女 2024-08-28 23:35:00

您可以在存储库中创建一个 shell 脚本,通过 git config 设置这些值。这将使学生能够看到他们自己是如何做到的,并且为他们提供了一种撤消本地设置的方法。

不幸的是,这不会是自动的。

例子:

#! /bin/sh
git config core.editor "ed"

You could create a shell script in the repo that sets these values through git config. That would allow the students to see how they do it themselves, and it gives them a way to undo their local settings.

Unfortunately, this wouldn't be automatic.

Example:

#! /bin/sh
git config core.editor "ed"
风吹短裙飘 2024-08-28 23:35:00

全局设置可以通过以下方式设置:git config --global

也许您应该首先让学生将配置文件(从其自己的存储库)克隆到他们的主目录。

Global settings can be set via: git config --global

Maybe you should first let the students clone the configuration file (from its own repository) to their home directories.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文