git-stash无法找到工作树 [英] git-stash unable to find work tree

查看:192
本文介绍了git-stash无法找到工作树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm trying to setup a git repository with a manually defined worktree via:

我试图通过手动定义的工作树设置git存储库。 / project1
git --git-dir =。 --work-tree = / Users / braitsch / projects / project1 init

cd /Users/braitsch/repos/project1 git --git-dir=. --work-tree=/Users/braitsch/projects/project1 init

添加位于/ Users / braitsch / projects / project1中的文件
通过:git添加somefile或git add。

如同调用git branch一样,提交工作正常

After running the above I can add files located in "/Users/braitsch/projects/project1"
via : git add somefile or git add .
Commits work fine as do calls to "git branch"

但是, git存储列表会抛出以下错误:

However, git stash list throws the following error:


致命:/usr/local/Cellar/git/1.7.4.4/libexec/git-core/git-stash不能使用
而无需工作树。

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

是否在用户定义的工作树中不支持存储?

Is stashing not supported in user defined work-trees?

git config --local core.worktree
echoes out : /Users/braitsch/projects/project1

任何想法将不胜感激!

-------- UPDATE --------

正如@jleedev在下面指出的那样,在尝试从工作树外部调用git stash时似乎出现了一个错误。但是我的解决方法是只需cd到工作树中,然后通过首先在gitdir的路径之前调用存储。不方便,我知道,但以下作品为隐藏命令:

As @jleedev noted below, there does appear to be a bug when attempting to call "git stash" from outside the worktree. However my workaround is to just cd into the worktree and then call stash by first preceding the path to the gitdir. Inconvenient, I know but the following works for the stash command:

git --git-dir="projects/proj1/.git" stash list

这个问题似乎不会影响其他股票命令,如add,commit,branch等等。就我所知,只是隐藏。

This issue doesn't appear to plague other stock commands like add, commit, branch, etc. Just "stash" so far as I can tell.

如果您希望脱离默认结构,让.git文件夹嵌套在您的工作树,您可能会发现以下步骤很有用:

If you are looking to break-away from the default structure of having your .git folder nested inside of your worktree, you might find the following steps useful:


  1. 创建一个您要存储git存储库的目录

  2. 创建一个目录,您可以在其中保留要跟踪的文件
    (这两个文件夹都可以位于文件系统的任何位置)
  3. cd进入你的git仓库文件夹并运行:

  1. create a directory where you'd like to store your git repository
  2. create a directory where you want keep the files your going to track (both of these can be anywhere on your file system)
  3. cd into your git repository folder and run:

  git --git-dir=. --work-tree="path-to-your-project-folder" init

这会init一个新的存储库并将其链接到您的外部工作文件夹。


This will init a new repository and link it to your external worktree folder.

运行标准添加,删除,分支,提交命令,cd到你的git仓库并照常运行你的命令。
然而,要运行存储,请务必cd进入您的工作树,然后运行存储,如上所述,将命令与gitdir的路径相连。

To run standard add, delete, branch, commit commands, cd into the your git repository and run your command as usual. To run stash however, be sure to cd into your worktree and then run stash as I noted above prefacing the command with the path to your gitdir.

推荐答案

这可能是命令行为或错误报告中的错误。需要工作树并以脚本 1 实现的命令通过以下命令验证其存在:

This is either a bug in the command’s behavior or its error reporting. The commands which require a work tree and are implemented as scripts1 verify its presence with this command:

git rev-parse --is-inside-work-tree

如果你不是实际上是在工作树内,与错误信息暗示的内容相反。另一方面,用C实现的命令将 setup_work_tree 自动地 chdir s调用到工作树中。是否可以安全地修改 git-sh-setup 中的 require_work_tree 函数来匹配这个我不知道的问题。

which will fail if you are not actually inside the work tree, contrary to what the error message implies. The commands which are implemented in C, on the other hand, call setup_work_tree, which automatically chdirs into the work tree. Whether the require_work_tree function in git-sh-setup could safely be altered to match this I do not know.

1。 git-am.sh git-bisect.sh git-mergetool.sh git-pull.sh git-rebase--interactive.sh git-rebase.sh git-stash.sh git-submodule.sh

这篇关于git-stash无法找到工作树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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