git force push当前工作目录 [英] git force push current working directory

查看:165
本文介绍了git force push当前工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将git推送到远程,并且推送需要成为当前的工作副本。因为,推送来源是一个网络主机。所以,推送的文件需要被当前使用。我相信没有人会在主机上编辑文件:)

这个问题跟在这两个问题后面:
是否有可能在另一个git仓库中拥有一个git仓库什么不同的是,当启动一个git repo时,开关是否会被禁止?



编辑:bare repo不是我想要的,因为需要直接使用文件远程机器,并且需要在我放置它们的位置上找到。

Edit2:我的理解是,裸回购不会保留文件hieararchy,并保留根目录中的repo数据

解决方案

以下是关于如何在您的Web主机上创建git repo的分步说明将允许直接推送,将其设置为本地回购的远程设备,并对其进行更改。请注意,您需要ssh访问您的虚拟主机,并安装了git。



在您的虚拟主机(ssh'd)中:

 #在您的虚拟主机上创建一个空的回购;注意它的路径
mkdir站点
cd站点
git init

#配置它允许推送到当前签出分支
#而不抱怨(直接推送)
git config receive.denyCurrentBranch忽略

现在使用您的本地回购git命令:

 #创建对web主机远程的引用来推送
#/ path / to / the / repo是上面在web主机上做的repo的路径:
#它将是一个绝对路径或相对于你的SSH chroot(取决于主机)
git remote add deploy ssh:// your_user @ your_host / path / to / the / repo

#最后,推送您的更改!
git push deploy master

现在,您的更改已被推送到检出回购在网络主机上。但是,它们不会反映在工作目录中(也就是说,您的更改不会立即生效)。这是因为你已经直接推送到活动分支。完成后,您需要手动执行 git checkout -f


  • 更新工作目录

  • 创建 git post-receive 钩子自动完成。



要使用 post-receive 钩进行即时自动部署,请查看 git网站部署 howto。


I need to git push to remote, and that push need to be current working copy. Because, pushed source is a web host. So, pushed files need to be currently in use. I am sure no one will edit files at the host :)

This question is follow up of these 2 questions, Is it possible to have a git repo inside another git repo and what difference does --bare switch make when initing a git repo?

Edit: bare repo is not what I want, since files need to be directly used on remote machine, and need to be found on the locations where I put them.

Edit2: It is my understanding that bare repo doesn't keep the file hieararchy, and keep repo data in root directory

解决方案

Here is a step-by-step on how to create a git repo on your web host that will allow direct pushes, set it up as a remote for your local repo, and push changes to it. Note that you need to have ssh access to your web host, and have git installed.

On your web host (ssh'd in):

# create an empty repo on  your web host; note its path
mkdir site
cd site
git init

# configure it to allow pushes to the current checked-out branch
# without complaining (direct push)
git config receive.denyCurrentBranch ignore

Now with your local repo (run these git commands inside the repo):

# create the reference to the web host remote for pushing
# /path/to/the/repo is the path to the repo you made above on the web host:
# it will be an absolute path OR relative to your ssh chroot (depends on the host)
git remote add deploy ssh://your_user@your_host/path/to/the/repo

# finally, push your changes!
git push deploy master

Now, your changes have been pushed to the checked-out repo on the web host. However, they will not be reflected in the working dir (that is, your changes will not take effect immediately). This is because you have pushed directly to the active branch. To finish up, you need to either

  • manually perform a git checkout -f to update the working dir
  • make a git post-receive hook to do it automatically.

To have instant, automatic deployment with a post-receive hook check out this git site deployment howto.

这篇关于git force push当前工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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