问题描述
我有两个非裸露的git存储库,一个是我在其中开发的本地计算机,另一个是我在其上构建的服务器上.在本地存储库中,我有一个带有"git push -f server"的提交后钩子.每次我在本地计算机上提交时,更改都被推送到服务器.不幸的是,在远程git阶段,还原"了我的更改.我必须在服务器上手动执行"git reset HEAD --hard",这很烦人.如何告诉git接受更改而不进行恢复,或者如何在服务器上自动进行重置?我试图在服务器上添加一个接收后挂钩,但是它不起作用.
I have two non-bare git repositories, one a local machine in which I develop and the second on a server, on which I build. In the local repository I have a post-commit hook with "git push -f server". Each time I commit on a local machine, changes are pushed to the server.Unfortunately, on the remote git stages a "revert" of my changes. I have to do a "git reset HEAD --hard" on the server manually, which is quite annoying. How can I tell git to accept changes without staging a revert or how can I automatically do a reset on the server? I have tried to add a post-receive hook on the server, but it doesn't work.
我发现了一个类似的问题,但这无济于事(
I have found a similar question How do I push to the current git branch on remote, and have changes reflected immediately? , but it did not help (
推荐答案
您可以选择:
- 直接推送到一个非裸仓库,在这种情况下,您需要一个接收后钩子来签出新的
HEAD
,如"使用Git管理网站",并在"".
如您所述,赋予挂钩执行权是关键.
- pushing directly to a non-bare repo, in which case you need a post-receive hook to do checkout the new
HEAD
as described in "Using Git to manage a web site" and referenced in "Git Post-Receive Hook for Website Staging".
As you noted, giving execution right to the hook is key.
$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f
$ chmod +x hooks/post-receive
- 或者,您可以推送至裸仓库,并使用钩子切换到实时非裸仓库,拉来自裸仓库的新提交:
请参阅"远程裸机上的Git子模块"(您可以忽略该子模块方面) - or, you could push to a bare repo, and have an hook switching to the live non-bare repo, pulling the new commits from the bare repo:
See "Git submodule on remote bare" (you can ignore the submodule aspect)
相对于直接在非裸仓库中更改HEAD
,我倾向于第二种方法,它似乎更干净".
I tend to favor the second approach, which seems "cleaner" than directly changing HEAD
on a non-bare repo.
这篇关于推送后如何重设遥控器上的暂存更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!