使用 GIT 更新本地文件服务器上的文件

发布于 2024-10-15 22:14:38 字数 2082 浏览 1 评论 0原文

好的,我的机器上有一个存储库设置,我希望使用它来将更新推送到文件服务器上的某个位置。我使用以下内容进行克隆:

从计算机上的目录开始:

git init
git add .
git commit -m 'initial'
cd ../

然后克隆到文件服务器

git clone -bare testdir fileserverip/testdir

这克隆得很好,但如何使用 GIT 进行更新?与我之前使用 GIT 的经历不同,我不希望通过 SSH 或任何其他方式进行连接,那么我该如何设置推送呢?

编辑:

按照 Makis 的答案中提到的修改我的设置后,我在 git push 上收到以下错误

james-macbook:test2 james$ git push
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 506 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To xxxxxxxxxxxxxxxxxxx
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'xxxxxxxxxxxxxxxxxxx'
james-macbook:test2 james$ 

有人知道这意味着什么吗?

编辑:刚刚发现这个,认为这就是我需要的。 http://tiredblogger. wordpress.com/2009/11/09/creating-local-git-repositories-yeah-its-that-simple/

谢谢

OK so I have a repo setup on my machine and I'm looking to use this to push updates to a location on a fileserver. I used the following to clone:

Starting in dir on machine:

git init
git add .
git commit -m 'initial'
cd ../

Then cloning onto fileserver

git clone -bare testdir fileserverip/testdir

This clones fine but how can I use GIT to update? Unlike my previous experience with GIT I'm not looking to connect over SSH or anything so how can I set up the push?

EDIT:

After modifying my setup as mentioned in the answer by Makis I get the following errors on git push

james-macbook:test2 james$ git push
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 506 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To xxxxxxxxxxxxxxxxxxx
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'xxxxxxxxxxxxxxxxxxx'
james-macbook:test2 james$ 

Anyone know what this means?

EDIT: Just found this, think it's what I need. http://tiredblogger.wordpress.com/2009/11/09/creating-local-git-repositories-yeah-its-that-simple/

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹿港巷口少年归 2024-10-22 22:14:38

如果你可以通过 NFS 或 Samba 挂载服务器目录,那就很简单了。我会首先在服务器上创建裸存储库。然后在您的计算机上克隆空存储库并添加内容。

之后,一切都正常(拉、推)。

If you can mount the server directory via NFS or Samba, easy peasy. I would have created the bare repository on the server first. Then clone the empty repository on your machine and add the stuff.

After that, everything works like normal (pull, push).

初见 2024-10-22 22:14:38

听起来您正在尝试做一些与通过推送到 git 存储库来部署网站的常见问题非常相似的事情,因此有关如何执行此操作的信息同样适用于这种情况。

http://toroid.org/ams/git-website-howto

该网页描述了设置建立一个裸存储库(仅供参考,在上面列出的命令中,您使用的是 -bare 而不是 --bare,这可能是您遇到的一个问题)并使用 post-receive自动更新目录内容的钩子。 post-receive 挂钩通过调用 git checkout -f 来完成此操作,但指定了显式工作树(裸存储库没有工作树,因此通常该命令会失败)。

It sounds like you are attempting to do something very similar to the common question of deploying a website by pushing to a git repository so information on how to do that should equally apply to this situation.

http://toroid.org/ams/git-website-howto

That webpage describes setting up a bare repository (FYI in the command you listed above you had -bare instead of --bare which could be one problem you are encountering) and using a post-receive hook to update the contents of a directory automatically. The post-receive hook does this by calling git checkout -f but with an explicit work tree specified (bare repositories don't have work trees so normally that command would fail).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文