2015-11-28 16 views
0

我創建了我的服務器啓動時運行的shell腳本。 它的目標是從我的遠程倉庫拉最新更新:的Git拉的原因要刪除的文件

#!/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:[email protected]/my/path/to/repository.git $branch 

爲了測試它,我添加了一個名爲test.file文件到我的本地庫,致力於並將其推到遠程存儲庫。

起初,當我重新啓動我的服務器,我想,既然我/var/www/html文件夾中沒有任何改變的腳本未運行。

但是,當我做git status它顯示我test.file被標記爲刪除。

當我做git log我看我上次提交。

如果我手動運行我的服務器腳本 - 它完美的作品。

什麼原因呢?也許Ubuntu有某種防衛文件變化的層(我只是在黑暗中拍攝)?

UPDATE

這是一個日誌文件的輸出到我重定向既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引導命令運行了兩次。但它並不能解釋這種行爲。

+0

您可將這個腳本的輸出一些日誌文件,看看發生了什麼事? –

+0

@RomanZaytsev我將它添加到我的問題中。日誌看起來很好..不解釋文件的刪除.. –

回答

0

好了,所以我得到這個與從這裏其他的答案的工作有所幫助。 突然我在我的命令行中丟失了--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:[email protected]/my/path/to/repository.git $branch