git Git拉取并指定目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9155653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git pull and specify directory?
提问by jadent
i would like to run a git pull and specify the directory. some say using --git-dir and --work-tree should work but such as
我想运行一个 git pull 并指定目录。有人说使用 --git-dir 和 --work-tree 应该可以工作,但例如
git --git-dir=/var/www/.git --work-tree=/var/www pull
put this returns a "cannot be used without a working tree". The only time i can get this to work is if i use ".", ".." or any directory above the current directory
把这返回一个“没有工作树就不能使用”。我可以让它工作的唯一时间是如果我使用“.”、“..”或当前目录之上的任何目录
this post suggests maybe a bug? git pull while not in a git directory
这篇文章可能暗示了一个错误? git pull 而不是在 git 目录中
in the end i need to run a sudo git pull in a single line. i welcome any work arounds. thanks
最后,我需要在一行中运行 sudo git pull 。我欢迎任何变通方法。谢谢
采纳答案by araqnid
Use sudo and give the command as an argument to sh?
使用 sudo 并将命令作为参数提供给 sh?
Something like:
就像是:
sudo sh -c 'cd /dir && git pull'
回答by dotancohen
In the two years since this question was answered, Git 1.8 came out which supports calling git
in other directories using the -C
flag:
在这个问题得到回答后的两年里,Git 1.8 出现了,它支持git
使用-C
标志调用其他目录:
git -C /var/www pull
回答by manojlds
You are using --work-dir
, which is not the right paramter. It is --work-tree
and should work for what you want. Or you can just do cd /var/www && git pull
if you wanted the pull to be in a single command / line.
您正在使用--work-dir
,这不是正确的参数。它是--work-tree
并且应该为你想要的东西工作。或者,cd /var/www && git pull
如果您希望拉取在单个命令行/行中,您可以这样做。
回答by andrew
On Windows in MINGW64:
在 MINGW64 的 Windows 上:
git -C "C:\Trunk190117\crewcontrol-source" pull
or
或者
git -C /c/Trunk190117/crewcontrol-source pull