Git 存储 &工作树困境

发布于 2024-11-16 01:06:43 字数 1277 浏览 3 评论 0原文

我很难让 Git 与我的用户定义工作树配合,该工作树存在于包含 .git 目录的文件夹外部

基本上设置是这样的:我有两个目录,一个名为“git-worktree”,其中包含我想要跟踪的文件和文件。另一个称为“git-dir”,其中包含存储库的 .git 文件夹,也称为 GIT_DIR。

我通过 cd'ing 进入文件夹“git-dir”并运行来初始化存储库:

git --git-dir=./.git --work-tree=/Users/braitsch/Test/git-worktree/ init

这成功地初始化了存储库,当我位于“git-dir”文件夹中时,我可以添加工作树中的文件,运行 git状态并提交它们。凉爽的。

当我尝试运行 git stash 时,我遇到了麻烦,它给了我一个错误:

fatal: /usr/local/git/libexec/git-core/git-stash cannot be used without a working tree.

现在这是无意义的,因为我知道(或者至少我认为)我已经将工作树设置为“ git-worktree”文件夹,其中包含我要跟踪的文件。

git config --local -l 显示了以下内容:

core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.worktree=/Users/braitsch/Test/git-worktree
core.ignorecase=true

我什至尝试手动将 .git 文件夹添加到本地配置文件中,看看是否有帮助,但无济于事。

core.gitdir=/Users/braitsch/Test/git-dir/.git

现在关键来了。如果我将工作树设置为 git-dir 的父目录,Git stash 将起作用,例如,如果我将工作树设置为我的主目录。

core.worktree=/Users/braitsch/

所以我的问题是我缺少什么设置来告诉 Git 允许我的工作树存在于文件系统上的任何地方,而不仅仅是沿着 git-dir 的父路径存在备份到根目录?当然必须有一种方法来放置你的 git-dir &在告诉 Git 它们在哪里之后,你的工作树就在你想要的任何地方,并且一切正常?

I'm having difficulty getting Git to cooperate with my user-defined worktree that exists outside the folder that contains my .git directory.

Basically the setup is like this: I have two directories, one called "git-worktree" which houses the file I want to track & another called "git-dir" which contains the repository's .git folder aka the GIT_DIR.

I init the repository by cd'ing into folder "git-dir" and running:

git --git-dir=./.git --work-tree=/Users/braitsch/Test/git-worktree/ init

This successfully initializes the repository and while I'm in the "git-dir" folder I can add files that are in the work-tree, run git status and commit them. Cool.

The kick comes when I try to run git stash, which slaps me with the error:

fatal: /usr/local/git/libexec/git-core/git-stash cannot be used without a working tree.

Now this is nonsense, because I know (or at least I think) I have the work-tree set to the "git-worktree" folder that contains the files I want to track.

git config --local -l shows me the following :

core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.worktree=/Users/braitsch/Test/git-worktree
core.ignorecase=true

I even tried manually adding the .git folder to the local config file to see if that helps but to no avail.

core.gitdir=/Users/braitsch/Test/git-dir/.git

Now here comes the kicker. Git stash will work if I set the worktree to a directory that is a parent of the git-dir e.g. If I set the worktree to say my home directory.

core.worktree=/Users/braitsch/

So the question I have is what setting am I missing to tell Git to allow my worktree to exist anywhere on the filesystem, not just along a parent path of the git-dir back up to the root? Surely there must be a way to place your git-dir & your work-tree wherever you want and after telling Git where they are, and have everything work?

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

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

发布评论

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

评论(1

风为裳 2024-11-23 01:06:43
git --git-dir=<your path> --work-tree=<work tree path> stash

应该有效。您尝试过绝对路径吗?

更新:

似乎是一个错误。 --git-dir 选项的扩展功能是最近才添加的,一些命令(如 git stash)还没有新的实现。

git-stash 是一个 bash 脚本。您可以破解它并删除需要工作目录检查,然后 cd 进入工作文件夹。

git --git-dir=<your path> --work-tree=<work tree path> stash

should work. Have you tried absolute paths?

UPDATE:

seems to be a bug. The extended functionality of --git-dir option was only added recently and some commands like git stash don't have the new implementation yet.

git-stash is a bash script. You could hack it and remove the require working dir check then cd into the working folder.

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