使用Git管理WordPress的本地版,开发版和实时版

Dae*_*lan 2 git wordpress

我正在寻找使用git来管理WordPress项目的版本控制.

我通常有一个本地版本,一个Web服务器上的开发版本,客户端可以访问和测试,然后是一个实时版本.

我通常会在本地开发然后将我的更改推送到服务器上的repo,然后SSH到服务器上的dev文件夹并从repo中拉出来.当我想在实际站点上发布更改时,我将SSH连接到Web服务器上的live文件夹并从repo中提取.

这是我的困境.

我希望通过WordPress管理员(图片上传等)添加到本地版本的媒体被忽略,但我希望跟踪添加到Dev版本的媒体,所以当我拉到现场网站时,来自开发站点的媒体文件被拉.

有关制作此类作品的最佳方法的任何想法?

Mar*_*air 5

可能有更好的解决方案,但在类似的情况下,这两个选项对我来说都很好.假设您在本地工作的分支被调用,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
    
    Run Code Online (Sandbox Code Playgroud)

    现在假设您将一些文件上传到dev存储库,并想要提交它们:

    ssh server
    cd dev
    git add [whatever-media-files]
    git commit
    git push origin with-media
    
    Run Code Online (Sandbox Code Playgroud)

    现在要更新您的实时存储库,您可以这样做:

    ssh server
    cd live
    # git branch should show that you're on 'with-media'
    git fetch origin
    git merge origin/with-media
    
    Run Code Online (Sandbox Code Playgroud)

    要首先设置这些分支,您可以:

    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
    
    Run Code Online (Sandbox Code Playgroud)

    最后一点,假设您在开发者存储库中进行了一些更改,这些更改不仅仅是添加媒体,而且您希望在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
    
    Run Code Online (Sandbox Code Playgroud)

    在理想的世界中,你不需要经常做最后的步骤,但在实践中,知道如何做到这一点很好:)