2015-07-21 70 views
0

我学习Git和起初它似乎确定,但是当我试图把主文件中的变化我得到了这些错误:如何使用Git命令行推送更改?

Counting objects: 3, done. 
Writing objects: 100% (3/3), 232 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 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 C:\wamp\www\MyGit\myfirstgit 
! [remote rejected] master -> master (branch is currently checked out) 
error: failed to push some refs to 'C:\wamp\www\MyGit\myfirstgit' 

确定这里就是我所做的:

  1. 我创建我的主文件夹

    - C:\ WAMP \ WWW \ MyGit \ myfirstgit

  2. 结帐的文件夹到\ WWW

    - C:\瓦帕\ WWW \ myfirstgit

  3. 我创建的自述文件

    - C:\瓦帕\ WWW \ myfirstgit>回声 'TEST自述'>自述

  4. 检查状态 C:\瓦帕\ WWW \ myfirstgit> git的状态

    在分支主

    初始提交

    未跟踪文件: (使用“混帐添加...”中包括哪些将被提交)

    README 
    

    没有加入到承诺,但未跟踪文件存在(使用“混帐添加”追踪)

  5. 添加并提交更改

    C:\ WAMP \ WWW \ myfirstgit> git的添加自述

    C:\ WAMP \ WWW \ myfirstgit> git的承诺-m “我的第一个承诺”

    [主站(根提交)43bad4e]我的第一承诺 1文件改变时,1个插入(+) 创建模式100644自述

  6. 然后我推变化:

    - C: \ WAMP \ WWW \ myfirstgit>混帐推起源主

我也试过指出了目录,但错误:

C:\wamp\www\myfirstgit>git push origin C:\wamp\www\MyGit\myfirstgit 
fatal: remote part of refspec is not a valid name in C:\wamp\www\MyGit\myfirstgit 

然后我得到了上面的错误。

你能帮我吗?我是使用这个工具的新手。

谢谢。

+0

你git init的第一个文件夹? –

+0

问题在于您正在推送到非裸存储库。错误信息解释了这个问题。一个更加正常的工作流程是,你有一个裸机存储库是“权威”的存储库,而你的其他存储库则是从这个存储库中抽出来的。 –

+0

http://bitflop.com/tutorials/git-bare-vs-non-bare-repositories.html –

回答

3

git中远程存储库的典型用例是远程存储库仅用于与其他开发人员交换代码以及用于备份。这样的中央仓库通常是,这意味着它不包含工作目录;它只包含git历史记录。正如你所发现的那样,对非裸存储库进行更改有点麻烦。

如果要将第一个存储库保留为非裸设备(以便其具有工作目录,并且可以直接使用其中的文件),请转至C:\wamp\www\MyGit\myfirstgit并运行git checkout --detach HEAD。现在,推动应该起作用。但请注意,工作目录C:\wamp\www\MyGit\myfirstgit中的文件不会更改,因为存储库不会自动检出推送的更改(错误消息实际上表示您试图推送到活动分支,需要C:\wamp\www\MyGit\myfirstgit中的工作目录改变,而git不支持)。

否则,您可以重新创建远程回购裸露(假设只有内容是最初的承诺,在C:\wamp\www\myfirstgit仍然存在):C:\wamp\www\MyGit\myfirstgit下删除所有内容,包括隐藏.git目录,并运行git init --bare .那里;然后,从C:\wamp\www\myfirstgit再次推。

-5

使用

git push origin master 

但我会建议你不要使用主为你工作的分支所以这样做是为了创建一个新的分支

git checkout -b name_of_branch 

请确保您添加的分支远程过。从这里你可以继续你的正常过程。

git add -A 
git commit -m "commit message" 
git push origin name_of_branch 
+0

虽然这可能是一个很好的建议,但它不能解决OP的问题。 –

3

错误消息说这一切。您或者需要使用裸回购(推荐),或者如果您绝对需要非购买 - 请在此处执行git config receive.denyCurrentBranch warn,然后按。请注意,它只会更新.git目录中的文件,远程的工作副本将保持不变,直到有人在此处执行git reset --hard

在较新的git上,您可以将receive.denyCurrentBranch设置为updateInstead,它会在自动推送时更新。

+0

虽然技术上是正确的,但这个答案是无用的,除非你已经知道git是如何工作的,在这种情况下你不会问这个问题。 :-)太多特定的单词,没有足够的解释。 –