git noob正努力将开发计算机更改推向远程生产服务器 [英] git noob struggling to push development machine changes to remote production server

查看:106
本文介绍了git noob正努力将开发计算机更改推向远程生产服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对git很陌生。在可预见的未来,我将成为该项目的唯一开发者,所以我不担心在这一点上成为git专家。我只是想将我的更改推送到生产服务器。



开发机器有雪豹操作系统。我安装了git。使用git init,添加和提交。

远程生产服务器有ubuntu 10.我安装了git并使用了git init。

然后是ssh:/ /me@domain.com:00000/path_to_project_root/.git master:master



出现以下错误:

拒绝更新签出的分支:refs / heads / master。默认情况下,更新非裸仓库中的当前分支会被拒绝,因为它会使索引和工作树与推送的内容不一致,并且会要求'git reset --hard'将工作树匹配到HEAD,您可以在远程存储库中设置'receive.denyCurrentBranch'配置变量t'ignore'或'warn',以允许推送int当前分支;但是,这不是推荐除非你安排更新它的工作树来匹配你以其他方式推送的东西,为了压制这个消息并保持默认行为,将'receive.denyCurrentBranch'配置变量设置为'拒绝'... [remote rejected] master - >主人(麸皮ch当前已经被检出)



任何帮助都是值得赞赏的。

解决方案

在堆栈溢出中会非常频繁地询问此错误,并且如果您了解使用的术语,则需要了解的所有信息都将在错误消息中进行描述。在对你的问题的评论中,我已经链接到了一些处理同样错误的其他问题,但我会在这里添加一个快速总结。



基本在git中有两种类型的仓库 - 裸仓库和非裸仓库。当你需要处理代码时,你几乎总是使用一个非裸仓库,它在顶层有:


  • a .git 目录(包含项目的所有历史记录)

  • 该顶级目录中的所有其他内容,通常包括所有源代码'


后者是工作树。



裸仓库就像它自己的 .git 目录。例如,这意味着一个裸仓库永远不会有本地更改,并且您不能在任何可能会产生冲突的合并中进行合并。



如果您尝试推送到当前在非裸仓库中检出的分支,git有问题。如果它没有触及工作树,但更新了分支,那么来自 git status 的结果会突然显得非常混乱 - 任何在新提交中添加的文件分支将在 git status 中显示为已删除,并且您的本地更改以及新提交引入的更改将全部混淆。如果git只是更新你的工作树,它可能会覆盖你在那里的本地修改。



通常建议你只推送到裸存储库。然而,有各种各样的方法 - 例如,git FAQ中的以下答案建议一对:



在这种情况下,由于您希望推送到此存储库来部署您的代码,因此您可以尝试挂钩链接,这使得推入一个非裸仓库比安全抛出本地更改的钩子更安全 git reset --hard 或类似的。


i am new to git. in the foreseeable future i will be the only developer for the project in question so i am not worried about becoming a git expert at this point. i just want to push my changes to the production server.

development machine has snow leopard os. i installed git. used git init, add and commit.

remote production server has ubuntu 10. i installed git and used git init.

then "ssh://me@domain.com:00000/path_to_project_root/.git master:master"

getting the following error:

"refusing to update checked out branch: refs/heads/master. By default, updating the current branch in a non-bare repository is denied, because it will make the index and work tree inconsistent with what you pushed, and will require 'git reset --hard' to match the work tree to HEAD. You can set 'receive.denyCurrentBranch' configuration variable t 'ignore' or 'warn' in the remote repository to allow pushing int its current branch; however, this is not recommended unless you arranged to update its work tree to match what you pushed in som other way. To squelch this message and still keep the default behaviour, set 'receive.denyCurrentBranch' configuration variable to 'refuse'... [remote rejected] master -> master (branch is currently checked out)"

any help is appreciated.

解决方案

This error is asked about very frequently on Stack Overflow, and everything you need to know is described in the error message if you understand the terms used. In the comments on your question I've linked to a couple of other questions that deal with the same error, but I'll add a quick summary here anyway.

Essentially there are two types of repository in git - bare repositories and non-bare. When you need to work on code, you're almost always using a non-bare repository, which at the top level has:

  • a .git directory (containing all the history of your project)
  • everything else in that top level directory, typically all the source code you're working on

The latter is the "working tree".

A bare repository is like just the .git directory on its own. That means, for example, that a bare repository can never have local changes and you can't do any merge in one that might create conflicts.

If you try to push to the branch which is currently checked out in a non-bare repository, git has a problem. If it doesn't touch the working tree, but updates the branch, the results from git status will suddenly look very confusing - any files that were added in the new commits from the branch will appear as deleted in git status and your local changes and those introduced by the new commits will be all mixed up. If git just updates your working tree, it might overwrite local changes you had there.

Normally the recommendation is that you only push to bare repositories. However, there are various ways around that - for example, the following answer in the git FAQ suggests a couple:

In this case, since you want the push to this repository to deploy your code, you could try the hook linked to there, which makes pushing into a non-bare repository safer than just a hook that throws away the local changes with git reset --hard or similar.

这篇关于git noob正努力将开发计算机更改推向远程生产服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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