git force推送当前工作目录

yas*_*sar 11 git git-push

我需要git push to remote,而push需要是当前的工作副本.因为,推送源是一个Web主机.因此,推送的文件当前需要使用.我相信没有人会在主机上编辑文件:)

这个问题是这两个问题的后续问题, 是否有可能在另一个git repo中有一个git repo,并且在启动git repo时有什么区别--bare switch会做什么?

编辑:裸仓库不是我想要的,因为文件需要直接在远程机器上使用,需要在我放置它们的位置找到.

Edit2:据我所知,裸仓库不保留文件hieararchy,并在根目录中保存repo数据

she*_*mer 10

以下是如何在您的Web主机上创建一个允许直接推送的git仓库,将其设置为本地仓库的远程仓库,并推送更改的步骤.请注意,您需要具有对Web主机的ssh访问权限,并且已安装git.

在您的网络主机上(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
Run Code Online (Sandbox Code Playgroud)

现在使用您的本地repo(在repo中运行这些git命令):

# 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
Run Code Online (Sandbox Code Playgroud)

现在,您的更改已被推送到Web主机上的签出仓库.但是,它们不会反映在工作目录中(即,您的更改不会立即生效).这是因为您已直接推送到活动分支.要完成,你需要

  • 手动执行a git checkout -f以更新工作目录
  • 做一个git post-receive钩子来自动完成.

要使用post-receive钩子进行即时自动部署,请查看此git站点部署方法.


Dan*_*cer 6

这个问题真的很老了,但我找到了一个比这里列出的解决方案更好的解决方案(至少我的情况).

手动进行git config,因为Git的2.3.0:

另一个选项是"updateInstead",如果进入当前分支,它将更新工作目录(必须是干净的).此选项用于在通过交互式ssh无法轻松访问一侧时同步工作目录(例如,实时网站,因此要求工作目录清洁).

所以git config receive.denyCurrentBranch updateInstead(在接收存储库上)对我来说非常合适.它允许我自动推送更新接收存储库的工作目录(只要在推送发生时该工作目录是干净的).