我在我的mac上设置了远程git和本地git 我能够在远程机器(Linux)上创建一个git repo(git init myrepo) 添加了几个文件并且没有问题(git add,git commit -m“test”)
从我的本地我能够从遥控器克隆回购没有问题(git clone ssh:// user @ IP / Path)
到目前为止,没有问题。
我在本地创建了几个文件并使用git add和commit然后尝试使用git push origin master将它们推送到远程服务器
最初我收到了一条错误消息,搜索解决方案是直接在远程服务器上运行此命令: git config receive.denyCurrentBranch ignore
修复了问题,现在我能够成功推动:
$ git push origin master
git add test.sh
git add git*
git commit -m "Adding 2 new files and updating test.sh"
[master 4dd11a0] Adding 2 new files and updating test.sh
3 files changed, 109 insertions(+)
create mode 100644 gitHowToUrls.txt
create mode 100644 git_howto.txt
git push origin master
Counting objects: 7, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 1.91 KiB | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To ssh://root@IP/path/myrepo
ad4a8b2..4dd11a0 master -> master
$ git push -u origin master
Branch master set up to track remote branch master from origin.
Everything up-to-date
$ git push origin HEAD:master
Everything up-to-date
我甚至检查确保文件匹配
$ git ls-remote origin
52543130bff4f9f37a23b01b0c44c7549ab82dd9 HEAD
52543130bff4f9f37a23b01b0c44c7549ab82dd9 refs/heads/master
$ git ls-remote
From ssh://root@IP/path/myrepo
52543130bff4f9f37a23b01b0c44c7549ab82dd9 HEAD
52543130bff4f9f37a23b01b0c44c7549ab82dd9 refs/heads/master
然而,当我去我的远程仓库(root @ IP / path / myrepo) 我看不到任何新文件!知道我做错了吗?
我在远程服务器上运行了git log,我看到了所有的注释:
root@IP [myrepo]# git log
commit 52543130bff4f9f37a23b01b0c44c7549ab82dd9
Author: joe d <myemail@myemail>
Date: Sat Mar 22 15:56:30 2014 -0700
adding again, since first time didn't work
commit 4dd11a0235cdabe528f8755253989ce85df4fa8b
Author: joe d <myemail@myemail>
Date: Sat Mar 22 15:48:08 2014 -0700
Adding 2 new files and updating test.sh
commit ad4a8b224989dc2131b6a33f41b95ce8b2a5c96a
Author: joe d <myemail@myemail>
Date: Sat Mar 22 11:33:34 2014 -0700
test
commit 956ff16e081587fa59a8cec73fc383744c5c3a5e
Author: joe d <myemail@myemail>
Date: Sat Mar 22 18:32:30 2014 +0000
test
我的远程回购:
root@IP [myrepo]# ls -la
total 20
drwxr-xr-x 4 root root 4096 Mar 22 18:32 .
drwxr-x--- 6 joe nobody 4096 Mar 22 18:30 ..
drwxr-xr-x 8 root root 4096 Mar 22 18:38 .git
drwxr-xr-x 2 joe joe 4096 Mar 21 22:12 images
-rw-r--r-- 1 root root 992 Mar 22 18:31 index.html
我的当地回购:
localmachine:myrepo joe$ ls -la
total 32
drwxr-xr-x 8 joe 1668562246 272 Mar 22 16:42 .
drwxr-xr-x 3 joe 1668562246 102 Mar 22 11:33 ..
drwxr-xr-x 15 joe 1668562246 510 Mar 22 16:07 .git
-rw-r--r-- 1 joe 1668562246 445 Mar 22 16:42 gitHowToUrls.txt
-rw-r--r-- 1 joe 1668562246 3291 Mar 22 15:56 git_howto.txt
-rwxr-xr-x 1 joe 1668562246 81 Mar 22 15:43 test.sh
drwxr-xr-x 6 joe 1668562246 204 Mar 22 11:33 images
-rw-r--r-- 1 joe 1668562246 992 Mar 22 11:33 index.html
由于
新注意:
好的,所以我当然没有使用裸分支,我认为它是我在远程系统上运行的命令
git config receive.denyCurrentBranch ignore
我删除了本地和远程的repos并再次创建它(确实没有裸露)
然后尝试了这样的推送并收到了这个错误:
localrepo$ git push origin master
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 1.98 KiB | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
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 ssh://root@IP/path/myrepo
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://root@IP/path/myrepo'
这一次我输入了拒绝而不是忽略
git config receive.denyCurrentBranch refuse
运行git push会产生一条新的错误消息:
localRepo$ git push origin master
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 1.98 KiB | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
To ssh://root@IP/path/myrepo
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://root@IP/path/myrepo'
如何取消选中分支,以便我可以成功地从本地推送到远程仓库?
答案 0 :(得分:3)
你正在推动一个非裸仓库(由于receive.denyCurrentBranch
设置为忽略而有效)。
但有可能你的远程非裸机:
我删除了本地和远程的repos并再次创建它(确实没有裸露)
通过默认,receive.denyCurrentBranch
设置为“refuse
”,因此您的错误消息与此一致。
尝试将其设置为“忽略”,并且由于您的远程仓库位于master
,因此您的推送将会完成。
但你不会看到任何文件:你需要一个post-receive钩子来检查你的工作树或将它重置为HEAD,以便实际出现文件。
例如,请参阅“Git: making pushes to non-bare repositories safe”
我的post-receive挂钩看起来像这样:
export GIT_WORK_TREE=..
git checkout -f HEAD
原始问题的答案是在远程服务器上运行:
git config receive.denyCurrentBranch ignore
然后将
export GIT_WORK_TREE=.. git checkout -f HEAD
添加到您的gitrepo<PATH>/.git/hooks/post-receive
这就是诀窍,我现在能够将文件从我的本地推送到远程仓库!!!
答案 1 :(得分:0)
你可能正在推动bare repository。您必须在某个地方克隆它并从遥控器拉取以查看实时更改。
在myPath上创建一个裸存储库;你需要在myIP上登录shell:
现在您的推送工作正常,并按照@ VonC的说明配置您的接收后挂钩。