[英]Git pull cause file to be deleted
我创建了一个外壳脚本,该脚本在服务器启动时运行。 其目标是从我的远程存储库中获取最新更新:
#!/bin/sh
branch="production_test";
git --git-dir=/var/www/html/.git checkout -b $branch
git --git-dir=/var/www/html/.git pull https://username:password@bitbucket.org/my/path/to/repository.git $branch
为了对其进行测试,我将一个名为test.file
的文件添加到本地存储库中,将其提交并推送到远程存储库中。
起初,当我重新启动服务器时,我以为脚本没有运行,因为在我的/var/www/html
文件夹中没有任何更改。
但是 ,当我执行git status
它显示test.file被标记为已删除。
当我正在执行git log
我看到我的最后一次提交。
如果我在服务器中手动运行脚本,则可以正常运行。
是什么原因造成的? 也许Ubuntu
有某种保护文件更改的层(我只是在黑暗中拍摄)?
更新
这是我将std和stderr都重定向到的日志文件的输出:
fatal: A branch named 'production_test' already exists.
From https://bitbucket.org/my/path/to/repository.git
* branch production_test -> FETCH_HEAD
Merge made by the 'recursive' strategy.
test.file | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test.file
fatal: A branch named 'production_test' already exists.
From https://bitbucket.org/my/path/to/repository.git
* branch production_test -> FETCH_HEAD
Already up-to-date.
这是重启后git status
命令的输出:
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: test.file
我可以从输出中得知bash脚本可能通过2 rc.d引导命令运行了两次。 然而,它并不能解释这种行为。
好的,所以我可以在其他答案的帮助下使用它。 显然,我在命令行中缺少--work-tree
配置,所以我只添加了:
--work-tree=/var/www/html/
在我的命令中,它起作用了。
可以说我真的很了解它的作用,因为我从未更改过存储库的工作树中的任何内容-但至少它可以工作。
这是我的最终脚本:
#!/bin/sh
branch="production_test";
git --git-dir=/var/www/html/.git --work-tree=/var/www/html/ checkout -b $branch
git --git-dir=/var/www/html/.git --work-tree=/var/www/html/ pull https://username:password@bitbucket.org/my/path/to/repository.git $branch
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.