从不同的目录执行 git pull
我正在配置 calimoucho (一个小游戏连续集成服务器),为了让它工作,我需要运行从外部提取克隆的 git hub 存储库的命令。
更准确地说,我将用一个例子来解释它。
我有以下存储库
cd /home/sas
mkdir apps
cd apps
mkdir myApp
cd myApp
git init
echo "my file" > file
git add .
git commit -m "initial commit"
只是一个愚蠢的测试存储库,我的应用程序应该在其中
现在我需要将该存储库克隆到签出文件夹。
cd /home/sas
mkdir calimoucho
cd calimoucho
mkdir checkout
cd checkout
git clone /home/sas/apps/myApp/
所以我有以下目录结构
~/apps
myapp
.git
file
~/calimoucho
checkout
myapp
.git
file
连续集成服务器必须将新更改从〜/ apps / myapp拉到〜/ calimoucho / checkout / myapp,从〜/ calimoucho运行命令行句子
我尝试使用以下命令
~/calimoucho$ git --git-dir=/home/sas/apps/myApp/.git --work-tree=/home/sas/calimoucho/checkout/myApp/ pull
,我得到 以下错误
fatal: /usr/lib/git-core/git-pull cannot be used without a working tree.
如果我不指定 --work-tree 选项,则会出现
,发出拉取,但更改将应用于 ~/calimoucho 文件夹而不是 ~/calimoucho/checkout/myApp知道如何更新克隆来自 ~/calimoucho 文件夹的存储库?
多谢
I'm configuring calimoucho (a little play continuos integration server), and for it to work I need to run a command to pull a cloned git hub repository from outside it.
to be more precise, I'll explain it with an example.
I have the following repository
cd /home/sas
mkdir apps
cd apps
mkdir myApp
cd myApp
git init
echo "my file" > file
git add .
git commit -m "initial commit"
Just a silly test repository where my app is supossed to be
Now I need to clone that repository to a checkout folder.
cd /home/sas
mkdir calimoucho
cd calimoucho
mkdir checkout
cd checkout
git clone /home/sas/apps/myApp/
so I have the following directory structure
~/apps
myapp
.git
file
~/calimoucho
checkout
myapp
.git
file
The continuos integration server will have to pull new changes from ~/apps/myapp to ~/calimoucho/checkout/myapp, running a command line sentence from ~/calimoucho
I try with the following command
~/calimoucho$ git --git-dir=/home/sas/apps/myApp/.git --work-tree=/home/sas/calimoucho/checkout/myApp/ pull
and I get the following error
fatal: /usr/lib/git-core/git-pull cannot be used without a working tree.
if I don't specify the --work-tree option, the pull is issued, but changes are applied to ~/calimoucho folder instead of ~/calimoucho/checkout/myApp
any idea how to update the cloned repo from the ~/calimoucho folder?
thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我也有这个疑问。我在 git 文档中找到了答案(https://git-scm.com/docs/git)。
运行命令
回答这个问题的具体命令是
请注意,重要的是
-C
出现在pull
命令和任何其他 pull 选项之前可以在命令末尾指定。在上面的示例中,git clone 命令将设置默认远程存储库 ~/apps/myapp,因此不需要指定远程存储库。I had this question, too. I found the answer in the git documentation (https://git-scm.com/docs/git).
Run the command
The specific command to answer this question is
Note that it is important
-C <git-working-directory>
comes before thepull
command and any additional pull options can be specified at the end of the command. In the example above, thegit clone
command would have setup the default remote repository ~/apps/myapp so it is not required to specify the remote repository.git -C ~/Documents/blar/blar/directory/ pull
经过几个小时的搜索后,这对我有用。我在 Mac 上的终端上。
git -C ~/Documents/blar/blar/directory/ pull
This worked for me after hours of searching. I'm on a Mac in Terminal.
这个对我有用:
我在更新后挂钩中使用它来自动拉取并重新启动我的测试服务器上的 pm2。
This one worked for me:
I'm using it inside a post-update hook to automatically pull and restart pm2 on my test server.
就我而言,这是唯一有效的解决方案:
In my case, this is only working solution:
您不应将工作树设置为与 git-dir 变量不同的存储库。我认为当您不希望 .git 文件夹与工作树位于同一目录中时,应该使用它们。而是尝试这个:
You should not set the work-tree to a different repository than the git-dir variable. I think they are meant to be used when you don't want the .git folder to be in the same directory as your working tree. Instead try this:
如果您的 git 版本不喜欢 git-working-directory 选项:
然后预先使用push-directory命令。
例如,这将从父目录中提取您的 git 项目(如果不存在则克隆):
In case your git version doesn't like the git-working-directory option:
Then use the push-directory command beforehand.
For example, this will pull your git project from parent directory (or clone if it doesn't exists):