我正在考虑使用 git 来管理 WordPress 项目的版本控制。
我通常有一个本地版本、客户端可以访问和测试的 Web 服务器上的开发版本,然后是实时版本。
我通常会在本地进行开发,然后将更改推送到服务器上的存储库,然后通过 SSH 进入服务器上的 dev 文件夹并从存储库中提取。当我想在实时站点上发布更改时,我通过 SSH 进入 Web 服务器上的实时文件夹并从存储库中提取。
这是我的困境。
我希望忽略通过 WordPress 管理员添加到本地版本的媒体(图像上传等),但我希望跟踪添加到开发版本的媒体,以便当我将来自开发版本的媒体文件 pull 到实时站点时网站已被 pull 。
对于让这样的事情发挥作用的最佳方式有什么想法吗?
最佳答案
可能有更好的解决方案,但这两个选项在类似情况下对我来说效果很好。假设您在本地工作的分支名为 master
并在您所有的存储库中远程 origin
指的是您推送到的裸存储库。
如果您的所有媒体都整齐地放入一个目录中,您可以拥有一个单独的存储库来跟踪媒体并将其添加为 submodule到开发和实时存储库。在本地副本中,您应该:
- [在您希望本地实时媒体的情况下]请注意不要 (a) 在您的子模块中提交,(b) 从子模块中推送,也不要 (c) 将子模块的新版本添加到您的
master
分支 - [在本地副本中根本不需要这些媒体的情况下]根本不更新和初始化子模块 - 只需将其路径添加到
.git/info/exclude
即使您的媒体位于不同的目录中,您仍然可以使用此方法,但是管理子模块有点麻烦,如果您有很多子模块,情况会变得更加烦人。
- [在您希望本地实时媒体的情况下]请注意不要 (a) 在您的子模块中提交,(b) 从子模块中推送,也不要 (c) 将子模块的新版本添加到您的
或者,您可以将开发和实时存储库保存在不同的分支上,例如
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
在理想的情况下,您不需要经常执行最后的步骤,但在实践中,知道如何做到这一点是很好的:)
关于git - 使用 Git 管理 WordPress 的本地、开发和实时版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5239683/