在www.hostingcompany.com/~/mysite.com上维护源代码的一种好的Git策略是什么? [英] What is a good Git strategy for maintaining source code on www.hostingcompany.com/~/mysite.com?

查看:45
本文介绍了在www.hostingcompany.com/~/mysite.com上维护源代码的一种好的Git策略是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与因此,假设托管公司为www.hostingcompany.com

So let's say the hosting company is www.hostingcompany.com

当我对它进行SSH时,我在~中,我将会看到

and when I ssh to it, I am in ~ and I will see

~/mysite.com
~/any_other_folders

有什么好的Git工作流程来对~/mysite.com中的所有源代码进行版本控制,并能够git clone到本地PC?这样我就可以在本地进行修改,然后发布一行并推送到存储库中,并使~/mysite.com上的所有代码都保持最新状态?

What is a good Git workflow to version control all source code in ~/mysite.com, and able to git clone to my local PC? And so that I can make modification locally, and then issue one line and push to the repo and have all code on ~/mysite.com up to date?

使用git repo,然后将sftp从本地PC转换为~/mysite.com是一种好方法吗?我不愿意这样做,因为很难查看所有内容是否都已同步.

Is using a git repo, and then sftp from local PC to ~/mysite.com a good way? I prefer not to do that as it is harder to see if everything is sync'ed.

推荐答案

直接从

Copying the answer straight from the related question where you already got it:

您有两个选择:

  1. 创建一个裸存储库(mysite.com.git)和一个非裸存储库(mysite.com).在裸存储库中,将post-update挂钩添加到git --git-dir=.../mysite.com pull

  1. Make a bare repository (mysite.com.git) and a non-bare repository (mysite.com). In the bare repository, add a post-update hook to git --git-dir=.../mysite.com pull

请注意,您可能希望通过使用-s标志从裸机进行克隆来创建非裸存储库,或者之后再设置.git/objects/info/alternates以避免复制所有数据.

Note, that you may want to create the non-bare repository by cloning from the bare one with -s flag or set up .git/objects/info/alternates afterwards to avoid copying all the data.

仅创建一个存储库,然后:

Make just one repository and:

  1. 卸下头部:git checkout master@{0}

git merge master

这里的原因是git拒绝修改已签出的分支,但是如果您取消签出该分支,则可以进行推送.然后,您将能够通过钩子更新工作目录(钩子是放置在存储库中hooks目录中的脚本).您可以创建一个单独的分支并签出该分支,也可以使用分离的HEAD"状态(如上面的建议git通过使用指向该分支的特殊引用"HEAD"来记住签出了哪个分支,但是如果您签出的内容不是分支,而是直接指向修订版本,称为独立分支",由于没有签出任何分支,因此您可以推送到其中的任何一个.)

The reason here is that git refuses to modify the checked-out branch, but if you uncheckout the branch, you will be able to push. And you will be able to update the working directory from a hook (hook is a script placed in hooks directory in the repository). You can either create a separate branch and check out that, or you can use the "detached HEAD" state (as suggested above—git remembers which branch is checked out by having a special reference "HEAD" that points to the branch, but if you check out something, that is not a branch, it is made to point to a revision directly and that's called a "detached branch" and since no branch is checked out, allows you to push to any of them).

仅创建一个存储库,然后:

Make just one repository and:

  1. 关闭支票签出分支"检查.

  1. Turn off the push-to-checked-out-branch check.

git reset --hard上添加一个post-update钩子,以便在按下时重新签出分支.

Add a post-update hook to git reset --hard to re-checkout the branch when pushed.

此选项仅对只读访问有效,因为该钩子每次按下都会丢弃任何本地更改.

This option is only valid for read-only access, because the hook will discard any local changes each time you push.

如果仅将其检出并使其具有只读访问权限,则第二个选项的效率会略高一些,但是如果在工作目录上运行其他命令,第一个选项会更安全(您可以擦除并重新创建工作目录复制而不用担心主仓库).另请参见此问题.

If it's just check out and have it accessed read-only, the second option is slightly more efficient, but if you run some other commands on the working directory, the first is safer (you can wipe and re-create the working copy without worrying about the main repo). See also this question.

添加了第三个选项.

这篇关于在www.hostingcompany.com/~/mysite.com上维护源代码的一种好的Git策略是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆