Git 忽略子目录中的 .git 目录

发布于 2024-08-30 06:20:17 字数 320 浏览 4 评论 0原文

我使用 git 作为备份工具和笔记本电脑和台式机之间 $HOME 目录的“漫游配置文件”。

我的问题是,在我的 $HOME 下,我有一个 Development 目录,其中包含我正在处理的多个 git 项目。 Git 不允许我添加子目录 .git 文件夹。因此,为了提交这些项目,我必须将更改推送到我的 $HOME git 存储库中,在笔记本电脑上拉取(它们是在其中创建的,并且 .git 目录存在)并提交。

我读过有关子模块的内容,但这并不是我真正想要的。我只是希望子 .git 文件夹像任何旧目录一样对待,这样我就可以移动它们并备份它们。

有人这样做过或者知道我会怎么做吗?

I'm using git as a backup tool and 'roaming profile' for my $HOME directory between laptop and desktop.

My problem is that under my $HOME I have a Development directory with multiple git projects I'm working on. Git will not allow me to add the subdirectories .git folders. So to commit to these projects I have to push the changes into my $HOME git repo, pull on laptop (where they were created and .git dir exsits) and commit.

I've read about submodules, but it's not really what I want. I just want the children .git folders to be treated like any old directory so I can move them around and back them up.

Has anyone done this or have an idea how I would?

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

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

发布评论

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

评论(4

慕巷 2024-09-06 06:20:17

不要这样做。这是一个坏主意,因为您正在创建版本存储库的版本备份。只需通过 rsync 创建备份(您仍然可以使用 git 对父版本进行版本控制)

Don't do it. It's a bad idea because you are creating a versioned backup of a versioned repository. Just create a backup by rsync (you can still version the parent using git)

原来分手还会想你 2024-09-06 06:20:17

我个人使用 git 同步一些点文件,例如 .profile 或 .vimrc。为了避免像你这样的问题,我的 git 位于 $HOME/dot 中,并且单个文件在 $HOME 中符号链接。

I'm personally using git to sync some dot-files like .profile or .vimrc. To avoid problems like yours my git is located in $HOME/dot and the single files are symlinked in $HOME.

哆兒滾 2024-09-06 06:20:17

我会推荐一个脚本,它首先备份您的 $HOME 下的每个 .git 项目:它将生成一个备份文件(仍在您的 $HOME 下)
请参阅 git 包 了解更多。

然后,您可以将这些备份(或“捆绑”)文件添加/更新到您的主 git 存储库(其中包含除 .git 项目之外的所有 $HOME

最后,您可以导出所有使用相同的 Git 备份技术 (git bundle) 将 $HOME 作为一个文件。

I would recommend a script which would first backup every .git projects you have under your $HOME: it will produce one backup file (still under your $HOME)
See git bundle for more.

And then, you can add/update those backup (or "bundle") files to your main git repo (which contains all of your $HOME except the .git projects)

Finally, you can export all of your $HOME as one file with the same Git backup technique (git bundle).

梦里寻她 2024-09-06 06:20:17

过去我使用过 gibak,一个 Git 备份工具。除了处理文件属性之外,它还处理主目录中的 Git 存储库。

但有一项免责声明。我已经使用了一段时间,但有时备份会损坏。我没有调查过这一点,但我怀疑这与运行的应用程序不断将数据写入您的主目录有关。在某些时候,哈希值不匹配,您必须做一些聪明的事情才能修复它(或开始新的备份)。

至少尝试一下,它可能对你有用。我提到的问题也可能是Git造成的。由于我 1.5 年前尝试过此操作,因此它可能会同时得到修复。

In the past I have used gibak, a Git backup tool. Besides taking care of file attributes it also takes care of Git repositories inside your home directory.

One disclaimer though. I have used it for a while, but sometimes the backup became corrupt. I haven't investigated this, but I suspect it has to do with the fact that running applications constantly write data to your home directory. At some point the hashes mismatch and you have to do some smart things in order to get it fixed (or start a new backup).

At least give it a try, it may work for you. The problem I mentioned might also be caused by Git. Since I tried this 1.5 years ago, it might be fixed in the meantime.

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