管理本地配置文件的git存储库的有效方法 [英] Efficient way to manage a git repository for local config files

查看:140
本文介绍了管理本地配置文件的git存储库的有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我存储了我的配置文件(〜/ .bashrc 〜/ .emacs 〜/ emacs 等)在git中。我配置这个的方法只是在主目录中添加一个git仓库。



我发现这种方法有一些问题:


  • git gui 需要永久使用,因为它会递归扫描整个主目录。

  • 我有时不小心将文件添加到配置回购,应该去一个新的回购(我创建一个新的项目,比如〜/ projects / foo ,忘记它还没有初始化一个git repo,然后在 foo 目录中执行 git add bar.xyz 。添加到配置仓库)。



我不确定将git存储库嵌套在已具有git仓库,但我还没有遇到任何根本性的问题。



有没有更好的方法,或者这是人们存储本地配置文件的标准方式在git中?

解决方案

我保留我的点文件像你这样的Git仓库 - 我的主目录是Git仓库。




$ git gui code>:我很少使用它,所以我不确定它的性能如何受到很多未跟踪文件的影响。但是,我确实有一个〜/ .gitignore 文件,它只包含 * 。也许忽略所有事情会加速 git gui 给你。 偶然添加文件:创建<$只需包含 * 的文件也可以解决在您忘记使用文件时无意中将文件添加到dotfiles存储库的问题初始化一个新的项目库(如果你真的要添加文件,它会告诉你使用 -f )。




一些注意事项:

>


  • 我将〜/ .gitignore 设置为<$ c的主要原因$ c> * 使得 git status 不会显示我的主目录中的每个文件。它迫使我一直使用 git add -f ,这有点令人讨厌,但没有那么重要。


  • 习惯使用 git clean -dx 而不是 git clean -dxf 。你必须记得在新的项目库中运行 git config clean.requireForce false ,但它会阻止你意外删除你的主目录中的所有文件if您不在您认为自己所在的目录中。

  • Git有时会决定重置文件权限。如果你想在你的Git仓库中保存敏感文件( chmod og-rwx ),这可能会很糟糕。我通过一个后结帐钩子来处理这个问题,该钩子修复了某些文件和目录的权限(例如,〜/ .ssh / authorized_keys )。

I store my config files (~/.bashrc, ~/.emacs, ~/emacs, etc.) in git. The way I configured this was simply to add a git repository in the home dir.

I found this approach has some problems:

  • git gui takes forever, because it recursively scans the whole home dir.
  • I sometimes accidentally add files to the config repo that should go to a new repo (I create a new project, say in ~/projects/foo, forget it doesn't yet have a git repo initialized, and execute git add bar.xyz in the foo directory. This results in a file being added to the config repo).

I'm not sure it is wise to have git repositories nested under a directory that already has a git repository, although I haven't yet encounter any fundamental problems with this.

Is there a better approach, or is this a standard way in which people store local config files in git?

解决方案

I keep my dotfiles in a Git repository like you do—my home dir is a Git repository.

  • git gui: I rarely use it, so I'm not really sure how its performance is impacted by lots of untracked files. However, I do have a ~/.gitignore file that simply contains *. Perhaps ignoring everything will speed up git gui for you.

  • Accidentally adding files: Creating a ~/.gitignore file that simply contains * also solves the problem of accidentally adding a file to your dotfiles repository when you forget to initialize a new project repository (it'll tell you to use -f if you really want to add the file).

  • I've never had a problem with nested repositories.

Some notes:

  • The main reason why I set my ~/.gitignore to * is so that git status doesn't show every file in my home directory. It forces me to use git add -f all the time, which is a bit annoying, but not that big of a deal.

  • Get in the habit of using git clean -dx instead of git clean -dxf. You'll have to remember to run git config clean.requireForce false in new project repositories, but it'll prevent you from accidentally deleting all of your files in your home directory if you're not in the directory you think you're in.

  • Git sometimes decides to reset file permissions. This can be bad if you want to keep sensitive files (chmod og-rwx) in your Git repository. I handle this via a post-checkout hook that fixes permissions of certain files and directories (e.g., ~/.ssh/authorized_keys).

这篇关于管理本地配置文件的git存储库的有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆