簡體   English   中英

使用Git管理WordPress的本地,開發和實時版本

[英]Managing local, dev and live versions of WordPress with Git

我正在尋找使用git管理WordPress項目的版本控制。

我通常有一個本地版本,一個Web服務器上的開發版本,客戶端可以在該版本上進行訪問和測試,然后是實時版本。

我通常將在本地進行開發,然后將所做的更改推送到服務器上的存儲庫中,然后將SSH放入服務器上的dev文件夾中並從存儲庫中提取。 當我想在實時站點上發布更改時,我通過SSH進入Web服務器上的實時文件夾並從存儲庫中提取。

這是我的困境。

我希望忽略通過WordPress管理員添加到本地版本的媒體(圖像上傳等),但是我希望跟蹤添加到Dev版本的媒體,因此當我將其拉到實時站點時,會將來自開發站點的媒體文件拉出。

有什么想法可以使類似這種工作的最佳方式嗎?

可能有更好的解決方案,但是在類似情況下,這兩個選項對我來說效果很好。 假設您在本地工作的分支稱為master並且在所有存儲庫中,遠程origin指您推送到的裸存儲庫。

  1. 如果所有媒體都整齊地放在一個目錄中,則可以有一個單獨的存儲庫來跟蹤媒體,並將其作為子模塊添加到開發和實時存儲庫中。 在本地副本中,您應該:

    • [在需要本地實時媒體的情況下]小心不要(a)在子模塊中提交,(b)從其推送或(c)在master分支中添加新版本的子模塊
    • [在您的本地副本中根本不需要那些媒體的情況下]根本不更新和初始化子模塊-只需將其路徑添加到.git/info/exclude

    即使您的媒體位於各個目錄中,您仍然可以使用此方法,但是管理子模塊有些麻煩,如果有很多子模塊,則會變得更加煩人。

  2. 另外,您可以將開發庫和活動存儲庫保留在不同的分支上,稱為with-media ,該分支始終與master相同,但是提交會在歷史記錄的末尾添加介質。 您可以使用git rebase維持這種情況。 例如,如果您剛剛在本地進行了一些要推送的更改,則可以執行以下操作:

     git push origin master ssh server cd dev # git branch should show you that you're on 'with-media' git fetch origin git rebase origin/master 

    現在,假設您將一些文件上傳到dev存儲庫,並想要提交它們:

     ssh server cd dev git add [whatever-media-files] git commit git push origin with-media 

    現在,要更新您的實時存儲庫,您可以執行以下操作:

     ssh server cd live # git branch should show that you're on 'with-media' git fetch origin git merge origin/with-media 

    首先要設置這些分支,您需要執行以下操作:

     ssh server cd dev # git branch should show that you're on 'master', since you haven't created # the other branch yet: git checkout -b with-media git push origin with-media cd ~/live git fetch origin git checkout -t origin/with-media 

    最后一點,假設您在dev存儲庫中進行了一些更改,而不僅僅是添加媒體,並且您希望在master分支中進行這些代碼更改。 然后(在您執行任何操作之前!),您需要使用git rebase -i origin/master重新排序歷史記錄。

      ssh server cd dev git rebase -i origin/master # Reorder the lines so that the non-media commits are first (earliest) in the file. # Save the file and exit your editor. # Now find the SHA1 sum (object name) of the last commit that has non-media changes. # (The object name of the commits will have been changed by the rebase.) git log --oneline # Let's say that was commit f414f3l. Then you can push just the history up to and # including that commit back to the master branch with: git push origin f414f3l:master # Also push your 'with-media' branch back: git push origin with-media 

    在理想的世界中,您不需要經常執行最后的步驟,但是在實踐中,最好知道如何執行此步驟:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM