git push origin master不推送文件 [英] git push origin master not pushing the files

查看:158
本文介绍了git push origin master不推送文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的mac上安装了远程git和本地git
我能够在远程机器上(Linux)创建git repo(git init myrepo)
添加了几个文件,问题(git add,git commit -mtest)

从我的本地我能够从远程克隆回购没有问题(git clone ssh:/ / user @ IP / Path)

到目前为止没有问题。



我在本地创建了几个文件并使用git添加和提交,然后试图推送他们到远程服务器使用git push origin master

最初我收到一条错误消息,并搜索解决方案是运行此命令直接在远程服务器上:
git config receive.denyCurrentBranch ignore



解决了这些问题,现在我可以成功推送:



$ git push origin master

  git add test.sh 
git add git *
git commit -m添加2个新文件并更新test.sh
[master 4dd11a0]添加2个新文件并更新test.sh
更改3个文件,109个插入(+)
创建模式100644 gitHowToUrls.txt
创建模式100644 git_howto.txt
git push origin master
计数对象:7,完成。
使用多达8个线程的增量压缩。
压缩对象:100%(5/5),完成。
写作对象:100%(5/5),1.91 KiB | 0字节/秒,完成。
总共5(delta 0),重用0(delta 0)
到ssh:// root @ IP / path / myrepo
ad4a8b2..4dd11a0 master - > master

$ git push -u origin master

 设置分支主设备以从原点跟踪远程分支主设备。 
所有最新的

$ git push origin HEAD :master

 所有最新的

我甚至检查过以确保文件符合

$ git ls-remote origin

  52543130bff4f9f37a23b01b0c44c7549ab82dd9 HEAD 
52543130bff4f9f37a23b01b0c44c7549ab82dd9 refs / heads / master

$ git ls-remote

 从ssh:// root @ IP / path / myrepo 
52543130bff4f9f37a23b01b0c44c7549ab82dd9 HEAD
52543130bff4f9f37a23b01b0c44c7549ab82dd9 refs / heads / master

但是,当我到我的远程仓库时(root @ IP / path / myrepo)
我可以'没有看到任何新文件!任何想法我做错了什么?



我跑远程服务器上的git日志,我看到我所有的笔记:

  root @ IP [myrepo]#git log 
commit 52543130bff4f9f37a23b01b0c44c7549ab82dd9
作者:joe d< myemail @ myemail>
日期:星期六3月22日15:56:30 2014-0700

再次添加,因为第一次没有工作

提交4dd11a0235cdabe528f8755253989ce85df4fa8b
作者:joe d< myemail @ myemail>
日期:Sat Mar 22 15:48:08 2014 -0700

添加2个新文件并更新test.sh

提交ad4a8b224989dc2131b6a33f41b95ce8b2a5c96a
作者: joe d< myemail @ myemail>
日期:Sat Mar 22 11:33:34 2014 -0700

test

commit 956ff16e081587fa59a8cec73fc383744c5c3a5e
作者:joe d< myemail @ myemail>
日期:3月22日星期六18:32:30 2014 +0000

测试

我的远程回购:

  root @ IP [myrepo]#ls -la 
共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
$ b $ p我的本地回购:

  localmachine:myrepo joe $ ls -la 
共计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忽略

我已经删除了本地和远程的repos,并重新创建了它(肯定没有空)。

然后试图像这样推送并收到此错误:

  localrepo $ git push origin master 
计数对象:6,完成。
使用多达8个线程的增量压缩。
压缩对象:100%(5/5),完成。
写作对象:100%(5/5),1.98 KiB | 0字节/秒,完成。
总计5(增量0),重用0(增量0)
远程:错误:拒绝更新检出分支:refs / heads / master
remote:错误:默认情况下,更新当前分支在非裸仓库
remote:error:被拒绝,因为它会使索引和工作树不一致
remote:错误:与你推送的内容相同,并且需要'git reset - 很难'匹配
remote:error:工作树到HEAD。
remote:错误:
remote:错误:您可以在远程存储库中将'receive.denyCurrentBranch'配置变量设置为
remote:error:'ignore'或'warn',以允许推入
remote:错误:当前分支;然而,除非你
remote:error:安排它更新它的工作树来匹配你在
remote:error:other方面推送的内容,否则不建议这样做。
remote:error:
remote:error:为了压制此消息并保持默认行为,请将
remote:error:'receive.denyCurrentBranch'配置变量设置为'拒绝'。
到ssh:// root @ IP / path / myrepo
! [remote rejected] master - > master(分支目前已检出)
错误:未能将某些文件推送到'ssh:// root @ IP / path / myrepo'

这一次,我输入了拒绝而不是忽略

  git config receive.denyCurrentBranch拒绝

运行git push会产生一个新的错误信息:

  localRepo $ git push origin master 

计数对象:6,完成。
使用多达8个线程的增量压缩。
压缩对象:100%(5/5),完成。
写作对象:100%(5/5),1.98 KiB | 0字节/秒,完成。
总共5(delta 0),重用0(delta 0)
remote:error:拒绝更新签出分支:refs / heads / master
到ssh:// root @ IP /路径/ myrepo
! [remote rejected] master - > master(分支目前已检出)
错误:未能将某些文件推送到'ssh:// root @ IP / path / myrepo'

如何取消选中分支,以便我可以成功从本地推送到远程回购?

解决方案

您正在推动非裸回购(因为 receive.denyCurrentBranch 被设置为忽略)。



但它有可能是您的远程非裸回购:


  • 检出了一个不同于master的分支(并且由于您推送给master,所以工作树的内容不会改变)
  • 或者检出了一个提交(意味着你处于分离的HEAD状态,你可以通过一个git分支进行确认回购,查看是否有任何这些分支被标记为检出或不)。


    $ hr

    <

    blockquote>

    我已经删除了本地和远程的repos,并重新创建了它>由 default receive.denyCurrentBranch 设置为'拒绝',所以你的错误消息是一致的w



    尝试在'ignore'上设置它,并且由于您的远程仓库在 master 上,



    但你不会看到任何文件:你需要一个post-receive钩子来检查你的工作树或重置它为HEAD,文件实际出现。



    请参阅 Git:安全地推送非裸露的存储库


    我的post-receive钩子看起来像这样:




      export GIT_WORK_TREE = .. 
    git checkout -f HEAD






    OP 在评论中报告


    原始问题的答案i s运行在远程服务器上:



      git config receive.denyCurrentBranch忽略




    然后添加 export GIT_WORK_TREE = .. git checkout -f HEAD 到您的gitrepo < PATH> /。git / hooks / post-receive



    这个技巧,我现在可以推送文件从我的本地到远程repo !!!


    I have setup my remote git and local git on my mac I was able to create a git repo (git init myrepo) on the remote machine (Linux) Added few files and committed them no problems (git add , git commit -m "test")

    From my local I was able to clone the repo from the remote with no issues (git clone ssh://user@IP/Path)

    So far so good no issues.

    I have created few files locally and used git add and commit then tried to push them to the remote server using git push origin master

    initially I received an error message and searching around the solution was to run this command directly on the remote server: git config receive.denyCurrentBranch ignore

    That fixed the issues and now I am able to push successfully:

    $ 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
    

    I even checked to make sure that the files match

    $ 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
    

    However when I go to my remote repo (root@IP/path/myrepo) I can't see any of the new files!!! Any idea what I am doing wrong?

    I ran git log on the remote server and I see all my notes:

    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
    

    My remote repo:

    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
    

    My local repo:

    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
    

    Thanks

    NEW NOTE:

    OK, so I wasn't using bare branch for sure, I think its the command I ran on the remote system

    git config receive.denyCurrentBranch ignore
    

    I have deleted both repos on local and remote and created it again (No bare for sure)

    Then attempted a push like so and received this error:

    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'
    

    This time round I entered refuse instead of ignore

    git config receive.denyCurrentBranch refuse
    

    Running git push generated a new error message:

    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'
    

    How do I uncheck the branch so I could successfully push from local to remote repo?

    解决方案

    You are pushing to a non-bare repo (which works because of the receive.denyCurrentBranch being set to ignore).

    But it it possible that your remote non-bare repo:

    • has checked out a different branch than master (and since you are pushing to master, the content of the working tree wouldn't change)
    • or has checked out a commit (meaning you are in a detached HEAD state, which you can confirm with a git branch inside that repo, to see if any of those branches is marked as checked out or not).

    I have deleted both repos on local and remote and created it again (No bare for sure)

    By default, receive.denyCurrentBranch is set to 'refuse', so your error messages are consistent with that.

    Try setting it on 'ignore', and since your remote repo is on master, your push will go through.

    But you won't see any file: you need a post-receive hook which would checkout your working tree or reset it to HEAD, for the files to actually appear.

    See for instance "Git: making pushes to non-bare repositories safe"

    my post-receive hook looks like this:

    export GIT_WORK_TREE=..
    git checkout -f HEAD
    


    The OP reports in the comments:

    the answer to the original issue is run this on the remote server:

    git config receive.denyCurrentBranch ignore 
    

    Then Add export GIT_WORK_TREE=.. git checkout -f HEAD To your gitrepo <PATH>/.git/hooks/post-receive

    That did the trick and I am now able to push files from my local to the remote repo!!!

    这篇关于git push origin master不推送文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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