使用`git --git-dir / path / to / git pull / path / to / other / bare-git master`不会自动更新工作树。为什么不? [英] Using `git --git-dir /path/to/git pull /path/to/other/bare-git master` doesn't automatically update the working tree. Why not?

查看:115
本文介绍了使用`git --git-dir / path / to / git pull / path / to / other / bare-git master`不会自动更新工作树。为什么不?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果我有两个本地存储库,则其中一个裸露在文件夹 express.git ,另一个非裸用文件夹内的工作树express,都在同一个父文件夹中,我可以执行命令 git从 express 文件夹中拉动../ express.git 。这会自动更新 express中的所有内容。



然而,如果我运行命令 git - -git-dir /home/cisw470p/stu006/express/.git pull /home/cisw470p/stu006/express.git master 从位于任一git存储库的位置,然后 express repo会拉动更改,但不会自动更新工作树。然后,我必须运行 git add。来添加所有更改,然后在 express 内进行另一次提交,现在一切都是为什么使用--git-dir选项的命令的长版本不会自动更新 express 的工作树 / code>?是否有这样的原因,或者我找到了一个bug?编辑:我只是试了一遍,但编辑了一个不同的文件,现在它的工作。如果你运行 git --git-dir = some / dir,那么你就可以运行 /.git pull ,默认情况下 git 会假定当前目录是工作树。不是 some / dir / .git 的父项,而是您当前的 pwd 。这意味着运行该命令将尝试更新当前目录,就好像它是工作树一样,并最终将文件写入不属于此处的 pwd 中。



适当的解决方案是将 - work-tree 标志与结合使用 - git-dir 来告诉它工作树在哪里。在这种情况下,你需要 git --git-dir = some / dir / .git --work-tree = some / dir pull 。然而,在实验之后,这里似乎还有第二个问题。如果您按原样尝试此命令,可能会告诉您没有工作树时无法使用git-pull。看来这里的问题是 git 需要它的工作树是一个绝对路径而不是相对路径。



你真正想运行的是 git --git-dir = some / dir / .git --work-tree =$ PWD/ some / dir pull 。或者,您可以尝试 cd some / dir&& git pull 。如果你不想改变你的cwd,你可以把它放在一个子shell中,比如(cd some / dir&&git pull)


I found a peculiar behavior with git, and I can reproduce it every time on my machine.

If I have two local repositories, one bare inside the folder express.git, and the other non-bare with a working tree inside the folder express, both in the same parent folder, I can do the command git pull ../express.git from inside the express folder. This automatically updates everything inside express.

However, if I run the command git --git-dir /home/cisw470p/stu006/express/.git pull /home/cisw470p/stu006/express.git master from a location no located in either git repository, then the express repo will pull changes, but won't automatically update the working tree. I then have to run git add . to add all changes and then make another commit from inside express and now everything is good.

Why doesn't the long version of the command using the --git-dir option not automatically update the working tree for express? Is there a reason for this, or did I find a bug?

EDIT: I just tried it again but edited a different file and now it worked. I'm completely lost.

解决方案

If you run git --git-dir=some/dir/.git pull, by default git will assume the current directory is the work tree. Not the parent of some/dir/.git, but your current pwd. This means that running that command will try to update the current directory as if it's the work tree and will end up writing files into your pwd that don't belong there.

The appropriate solution is to use the --work-tree flag in conjunction with --git-dir to tell it where the work tree is. In this case you'd want git --git-dir=some/dir/.git --work-tree=some/dir pull. However, after experimentation it seems there's a second problem here. If you try this command as-is, you'll probably be told git-pull cannot be used without a working tree. It seems the issue here is git needs its work tree to be an absolute path instead of a relative one.

What you really want to run is git --git-dir=some/dir/.git --work-tree="$PWD"/some/dir pull. Alternatively, you could just try cd some/dir && git pull. If you don't want to change your cwd, you can wrap this in a subshell, i.e. ( cd some/dir && git pull ).

这篇关于使用`git --git-dir / path / to / git pull / path / to / other / bare-git master`不会自动更新工作树。为什么不?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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