2014-02-14 31 views
2

我對Git相對來說比較陌生。在問我的問題之前,有一點關於我的工作流程。Git:刪除GitLab/GitHub倉庫中未跟蹤的文件而不影響生產服務器的文件

我最初把我的整個項目推到了GitLab,把這個repo克隆到了一個開發(源代碼主)和一個生產(原始產品)服務器上,並且自此建立了一個webhook,觸發了關於開發的git pull origin master請求服務器當我推到主分支。

一旦我對結果感到滿意,我將'master'分支與'production'分支合併在一起,該分支也爲生產服務器附加了webhook(git pull origin production)。由於我的項目主要是(90%)模板文件,我想從GitLab服務器倉庫中刪除一些文件(這將永遠不會改變,例如配置,系統文件),而不會影響(刪除)兩個文件開發和生產服務器。

我已經在我的本地副本上設置了一個.gitignore文件來解開這些文件。

但是,如何在GitLab服務器上「清理」回購,而不會在我的開發和生產服務器上刪除這些文件?

我發現這個: Untrack Files In Git Repos Without Deleting Them。這看起來像我的情況,但它沒有幫助。

我收到下面當我嘗試推到GitLab按照上述帖子手術後:

error: failed to push some refs to 'http://git.mygitlab.com/myproject.git' 
hint: Updates were rejected because the remote contains work that you do 
hint: not have locally. This is usually caused by another repository pushing 
hint: to the same ref. You may want to first integrate the remote changes 
hint: (e.g., 'git pull ...') before pushing again. 
hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

此外,如果任何人有我是否要去我的工作流程正確,那也就可以理解的任何建議。

回答

3

但是,如何在GitLab服務器上「清理」回購,而不會在開發和生產服務器上刪除這些文件?

這是最好的,如果你有機會到部署服務器,以:

  • git rm --cached PROD上這些文件(在production分支),並把它推到GitLab
  • git rm --cached這些文件上dev(在dev分支)並將其推送到GitLab
  • 本地拉,添加您的.gitignore文件。
+1

謝謝。這工作。 –

+0

很確定命令缺少「d」,應該是'git rm --cached'任何人都可以確認嗎? –

+1

@HighlyIrregular我確認了。我相應地修改了答案。 – VonC

相關問題