2011-03-08 125 views
2

我正在寻找使用git来管理WordPress项目的版本控制。使用Git管理WordPress的本地,dev和live版本

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

我通常会在本地开发,然后将我的更改推送到服务器上的回购,然后SSH进入服务器上的dev文件夹并从回购中拉出。当我想要将实时站点上的更改发布到Web服务器上的活动文件夹中并从回购站点拉出时,

这是我的困境。

我希望通过WordPress管理员(图片上传等)将媒体添加到本地版本中,但我希望将媒体添加到开发版本进行跟踪,这样当我将实况网站中的媒体文件dev站点被拉。

任何关于使这种工作的最佳方式的想法?

回答

5

对此可能有更好的解决方案,但这两种方案在类似情况下对我来说工作得很好。假设您在本地工作的分支名为master,并且在所有存储库中,远程origin指向您推送的裸仓库。

  1. 如果所有的媒体准确落入一个目录,你可以有一个独立的存储设备,跟踪媒体和补充,为submodule给DEV和现场信息库。在您的本地副本,你应该:

    • [在您希望在本地实时影音的情况]要小心,不要(一)提交你的子模块,(二)推进从它也不是(c)加入子模块的新版本,以你的master分支
    • [在情况下,你并不需要在所有的媒体在你的本地副本]不更新,并在所有初始化子模块 - 只需添加其路径.git/info/exclude

    即使您的媒体处于不同的目录中,您仍然可以使用此方法,但管理子模块有点痛苦,并且会得到ra如果你有很多它们,你会更加恼怒。

  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 
    

    现在假设您上传一些文件到开发资源库,并要提交它们:

    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 
    

    作为最后一个注意事项,假设您在开发库中进行了一些不仅仅是添加媒体的更改,而且您希望在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 
    

    在一个理想的世界中,你将不再需要经常做这些最后的步骤,但在实践中的好,知道该怎么做:)

+0

非常感谢您的详尽的解释。这有很大的帮助。 – Daelan 2011-03-10 14:24:04