如何通过 shell 脚本运行 git 命令?
我的服务器上有我的主存储库和两个克隆。
我的本地有一个克隆可供编辑。另一个副本位于我的服务器上的公共文件夹中,用于提取更改并实时查看它们。
我当前正在经历的例程是编辑本地 ->登录到我的服务器的公共文件夹并执行 git pull 以查看更新的更改。
我想使用 git hooks“post-receive”shell 脚本更改为公共文件夹并执行 git pull origin master...我似乎不知道如何正确执行此操作。我尝试使用:
cd /home/demo/public_html/example.com/public/ && `git status`
但我得到的返回是“不是存储库”
但是,如果我运行 cd /home/demo/public_html/example.com/public/ && ls
我将获取公共文件夹的内容(因此我正在移动到正确的位置)提前致谢!
更新:
应该提到我在有或没有蜱虫的情况下尝试这个
I have my main repo on my server and two clones.
One clone is on my local for editing. Another copy is on my server in the public folder to pull the changes and view them live.
The current routine I'm going through is edit local -> log into my server to the public folder and do a git pull to see the updated changes.
I would like to use the git hooks "post-receive" shell script to change into the public folder and do a git pull origin master...I just can't seem to figure out how to do this properly. I tried this using:
cd /home/demo/public_html/example.com/public/ && `git status`
But the return I get is "not a repository"
However, if I run cd /home/demo/public_html/example.com/public/ && ls
I WILL get the contents of the public folder (so I'm moving into the right place) Thanks in advanced!
UPDATE:
Should have mentioned I was trying this with and without ticks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在进行 git pull 或 git status 测试之前,首先尝试取消设置 GIT_DIR 环境变量。
First try unsetting the GIT_DIR env variable before doing the git pull or the git status for test.
我想你想要这样:
反引号用于捕获 shell 变量中命令的输出,例如:
将
ls
的输出放入变量x
中。I think you want this:
The backticks are used to capture the output of a command in shell variable, for example:
will put the output of
ls
into the variablex
.您实际上是否在 git status 周围包含反引号?也就是说,您是否正在编写
cd ... && `git status`
或cd ... && git 状态
?如果您正在编写第一个命令,那么它所做的就是评估 git status 命令,然后尝试将其结果解释为要执行的另一个命令。删除反引号,您应该只得到 git status 的结果,而不是错误,因为它试图将其结果解释为命令。Are you actually including the backquotes around
git status
? That is, are you writingcd ... && `git status`
orcd ... && git status
? If you're writing the first one, then what that's doing is evaluating thegit status
command, and then trying to interpret the results of that as another command to execute. Remove the backquotes, and you should just get the result ofgit status
, not an error as it tries to interpret its results as a command.