如何通过 URL 访问 git 存储库中的分支?
我一直计划使用 GIT 进行版本控制。然而,我心里有一个非常愚蠢的问题。
假设我有一台配置了 PHP 的服务器,我正在使用它来开发可以通过服务器名称/网站访问的网站。一旦我在该目录中初始化 git,它就会自动创建一个主存储库。如果我创建几个分支(Branch1、Branch2)等怎么办。
一旦我对 Branch1、Branch2 等进行更改...如何通过 URL 查看更改? 当我访问 sername/website 时,它会只显示 master 分支中存在的内容吗?
另外,如果我通过从一个分支执行 rm filename 来删除文件,我知道它也会从服务器中删除它。但是,如果我切换分支,我会看到该文件存在于该分支中,但不在服务器上。我觉得这很奇怪?如何访问不存在的文件? (我知道 git rm --cached 将文件保留在服务器上,并且只从分支中删除它......但我很好奇......)
I've been planning on using GIT for version control. However, I have a prolly stupid question in my mind.
Say I have a server with PHP configured and I am using it to develop websites that I can access by servername/website. Once I initialize git in that directory, it automatically creates a master repository. What if I create a few branches say (Branch1, Branch2) etc.
Once I make changes to Branch1, Branch2 etc ... how can I view the changes via a URL?
When I go to sername/website, will it show me only the contents of what is present in the master branch?
Also if I remove a file by doing rm filename from one branch, I know it also deletes it from the server. However if I switch branches, I see that the file exists within that branch, but not on the server. That seems weird to me? How can I access a file that doesn't exist? (I am aware that git rm --cached, keeps the file on the server and only deletes it from the branch ... but I was curious, nonetheless ...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,服务器将向您显示已检出的文件。
它不会从服务器中删除该文件,只是该分支中的提交(很可能是同一分支中后续的提交)不再在树中引用该文件。
不是真的,这会从当前 git 设置(在您正在使用的计算机上)的暂存区域中删除文件。
回到最初的问题,您可能可以设置一些 CGI 脚本来为您的网站签出不同的分支,但访问同一网站的每个用户仍然会看到相同的内容。
如果您希望通过网络界面查看您所做的更改,则应该查看 git-php 或类似的东西。
编辑由于您的评论的答案不短,我在这里添加...
不!每个分支都被克隆并存储在 .git 文件夹中,您一次只能签出一个分支(或一个提交)。您一次只能“查看”一个版本的代码,只有存储库中的所有内容也都存储在您计算机上的 .git 文件夹中。
一种(如果您没有太多分支,这是一种简单的方法)是拥有与分支一样多的克隆。像这样的东西:
Yes, the server will show you the files that are checked out.
It does not delete the file from the server, only that commit in that branch (and most probably the commits following in the same branch) do not reference that file anymore in the tree.
Not really, that deletes the file from the staging area in your current git setup (on the machine you are working on).
To come back to your original problem, you can probably setup some CGI script that would checkout a different branch for your website, but still every user accessing the same website will all see the same thing.
If you want a web interface to look at the changes you are making, you should look into git-php or something like that.
EDIT Since the answer to your comment is not short, I am adding here...
No ! Every branch is cloned and stored in the .git folder, you are checking out only one branch (or one commit) at a time. You "view" only one version of the code at a time, only everything in the repository is also stored on your computer in the .git folder.
One (easy way if you don't have too many branches) is to have as many clones as you have branches. Something like this :