V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
yakczh
V2EX  ›  问与答

git push origin master 报错

  •  
  •   yakczh · 2014-09-10 11:48:45 +08:00 · 3705 次点击
    这是一个创建于 3729 天前的主题,其中的信息可能已经有所发展或是发生改变。
    先建立orgin
    mkdir E:\g\gitsrc
    cd E:\g\gitsrc
    git init
    echo "some" > some.txt
    git add some.txt
    git commit -m'some '


    再clone到F:\下的gitwork
    git clone E:\g\gitsrc gitwork
    echo "apend data " >> some.txt
    git commit -m'append'
    git push origin master
    结果报错
    Counting objects: 5, done.
    Writing objects: 100% (3/3), 250 bytes | 0 bytes/s, done.
    Total 3 (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 inconsiste
    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 e:\g\gitsrc
    ! [remote rejected] master -> master (branch is currently checked out)
    error: failed to push some refs to 'e:\g\gitsrc'
    上面的命令是哪一步出错了?
    9 条回复    2014-09-10 23:05:43 +08:00
    lemontv
        1
    lemontv  
       2014-09-10 12:49:56 +08:00 via iPhone
    remote: error: By default, updating the current branch in a non-bare repository
    git init --bare
    aa65535
        2
    aa65535  
       2014-09-10 12:58:15 +08:00   ❤️ 1
    git init 初始化生成的属于 working repository (工作仓库);
    应该使用git init --bare 来初始化成 bare repository,这样才能接受 push。
    你这样干,报错是当然了。
    yakczh
        3
    yakczh  
    OP
       2014-09-10 13:07:45 +08:00
    @lemontv 这样可以 在f:\gitwork下 push origin master 但是在 E:\g\gitsrc 下看不到文件变动 是不是在E:\g\gitsrc 下还要操作才能看到更新?
    yakczh
        4
    yakczh  
    OP
       2014-09-10 16:30:04 +08:00
    @aa65535 git --bare init 这样生成的项目 里面的目录结构是 branches config description HEAD hooks info objects refs
    从本地F:\gitwork 下可git push origin master
    但在E:\g\gitsrc 里面怎么得到更新?
    aa65535
        5
    aa65535  
       2014-09-10 17:23:53 +08:00
    @yakczh bare repository 是不可以直接修改的,通过 clone 后的 working repository 修改,然后 push。
    yakczh
        6
    yakczh  
    OP
       2014-09-10 17:30:25 +08:00
    @aa65535 怎么样在bare repository看修改的变动? 是不是要看到 bare repository 里面的修改变动, 还需要再clone出另一个 working repository 来?
    aa65535
        7
    aa65535  
       2014-09-10 18:15:06 +08:00
    @yakczh bare repository 中可以使用 git log 的。
    可以这样理解:
    bare repository相当于server
    working repository相当于client
    jy01264313
        8
    jy01264313  
       2014-09-10 18:25:18 +08:00
    git remote add origin url 需要添加远程的 repo 吧
    lemontv
        9
    lemontv  
       2014-09-10 23:05:43 +08:00
    @yakczh
    建议你完整的读一遍 http://git-scm.com/book/zh
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5557 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 03:37 · PVG 11:37 · LAX 19:37 · JFK 22:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.