简体   繁体   English

无法将提交推送到远程存储库-GitHub

[英]Cannot push commits to a remote repository - GitHub

I have an Android project I was working on in Eclipse. 我有一个正在Eclipse中工作的Android项目。 I created an account for myself on github and pushed code within the project to the online remote repository using the GitHub for Mac client. 我在github上为自己创建了一个帐户,并使用Gi​​tHub for Mac客户端将项目中的代码推送到了在线远程存储库中。 Subsequently, I made a couple more minor commits to the code and all went well. 随后,我对代码进行了一些较小的提交,一切顺利。

Now the code has undergone some significant changes and when I try to commit using the Mac client, I get the following error message on Sync: 现在,代码已进行了一些重大更改,当我尝试使用Mac客户端进行提交时,在Sync上收到以下错误消息:
Sync Failed: Please commit all your changes before syncing.

To get around this, I tried the following: 为了解决这个问题,我尝试了以下方法:
1. Tried to use git push origin/master from the command line. 1.尝试从命令行使用git push origin/master This resulted in project/info/refs not found: did you run git update-server-info on the server? 这导致project/info/refs not found: did you run git update-server-info on the server?
2. I checked if the repository name, location etc. were all correct and they were. 2.我检查存储库名称,位置等是否正确,是否正确。

My question(s): 我的问题:
1. There are a large number of .class files which show up in the Changes section. 1.“更改”部分显示大量的.class文件。 Why do they show up given that .class files are included in .gitignore ? 鉴于.class文件包含在.gitignore ,为什么它们会出现? Now that they have shown up, is it necessary to select and commit them too? 现在它们已经出现了,是否也需要选择并提交它们?
2. What is the meaning of the error message above and how do I get rid of it? 2.上面的错误消息是什么意思,我该如何解决?

EDIT 1: 编辑1:
After the following commands: 在执行以下命令后:
1. git ls-tree -r master | grep .class 1. git ls-tree -r master | grep .class git ls-tree -r master | grep .class - this showed that .class files were also added to the repository. git ls-tree -r master | grep .class这表明.class文件也已添加到存储库中。
2. git rm **/*.class to remove all .class files from the repository. 2. git rm **/*.class .class从存储库中删除所有.class文件。
3. git commit -m "remove class files 3. git commit -m "remove class files
4. git push origin master results in: 4. git push origin master导致:

fatal: https://github.com/user/project.git/info/refs not found: did you run git update-server-info on the server?  

Also, running git status on the command line shows the following line: 另外,在命令行上运行git status显示以下行:

# On branch master
# Your branch is ahead of 'origin/master' by 16 commits.
#

Is this something of concern? 这值得关注吗?

I have been through a lot of threads on this topic and taken a look at stuff like SSH-keygen but I dont think that is the solution to my problem. 我在这个主题上经过了很多讨论,并研究了诸如SSH-keygen之类的东西,但是我不认为这是解决我的问题的方法。 I am a newbie to git and have used only cvs before, so please dumb-down your answers, if possible. 我是git的新手,以前只使用过cvs,因此,如果可能的话,请简化您的答案。

My .gitignore file: 我的.gitignore文件:

# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties

# Eclipse project files
.classpath
.project

# Proguard folder generated by Eclipse
proguard/

# Intellij project files
*.iml
*.ipr
*.iws
.idea/
*.class

*.class

*.class

*.jar

*.class

*.class

bin/dexedLibs/slf4j-android-1.6.1-RC1-e5ffa87f4686586f2e03d9069f131ba3.jar

*.class

You first need to push the commits to your local repository and THEN push the commits to the remote one. 您首先需要将提交推送到本地存储库,然后将提交推送到远程存储库。 This allows you to do very easy merges with the remote repository as every commit has a unique SHA id which is used to tell where your repository is in relationship to the remote repo. 这使您可以非常轻松地与远程存储库进行合并,因为每次提交都具有唯一的SHA ID,该ID用于告诉您的存储库与远程存储库的关系。

do the following: 请执行下列操作:

git add .
git commit -m "your commit message"
git push origin master    (NOT git push origin/master)

EDIT 编辑

Did you by chance change the name of the github repository? 您是否偶然更改了github存储库的名称? This SO question should shed some light. 这样的问题应该有所启发。

It is possible that you have committed the .class files in the repository already. 您可能已经在存储库中提交了.class文件。 In which case git will keep tracking them even if you put *.class in the .gitignore file. 在这种情况下,即使您将* .class放在.gitignore文件中,git也会继续跟踪它们。 Run git ls-tree -r master | grep .class 运行git ls-tree -r master | grep .class git ls-tree -r master | grep .class . git ls-tree -r master | grep .class If that gives any output you have committed .class files. 如果给出任何输出,则表示您已提交.class文件。 If so, try running git rm **/*.class and commit the change. 如果是这样,请尝试运行git rm **/*.class并提交更改。

You are not supposed to run git push origin/master you need to specify a remote and then (optionally) a branch. 您不应该运行git push origin/master ,而需要先指定一个远程节点,然后再选择一个分支。 Now git will try to parse origin/master as a remote. 现在,git将尝试将origin/master解析为远程origin/master Use git push origin master instead (use a space not a /). 请改用git push origin master (使用空格而不是/)。 origin/master is a branch that you should not be changing yourself anyway. origin/master是一个分支,无论如何您都不应该改变自己。

Besides you have *.class multiple times in your .gitignore. 此外,您在.gitignore中多次拥有* .class。 Multiple occurrences will not change the behavior of git. 多次出现不会改变git的行为。

' git commit . git commit。 ' will commit all your changes. '将提交所有更改。

Maybe you can try it... ( I'm not sure, just an idea ) 也许您可以尝试一下...(我不确定,只是一个主意)

The problem was that I was signed in to GitHub 's Mac client using a personal ID. 问题是我使用个人ID登录到GitHub的Mac客户端。 This personal ID was not registered as a collaborator on the project. 该个人ID未在项目中注册为协作者。 Adding my personal account as a collaborator (an ugly work-around) solved the problem. 将我的个人帐户添加为协作者(一个丑陋的解决方法)解决了该问题。 I was able to commmit changes to the repository. 我能够提交对存储库的更改。

Other suggestions which I found useful: 我发现有用的其他建议:
- Removing .class files from the repository. -从存储库中删除.class文件。
To check if .class files were being tracked: git ls-tree -r master | grep .class 要检查是否跟踪了.class文件,请执行以下操作: git ls-tree -r master | grep .class git ls-tree -r master | grep .class
To remove them from the repo and commit: git rm **/*.class followed by git commit -m "your message goes here" 要将它们从仓库中删除并提交: git rm **/*.class然后是git commit -m "your message goes here"
To push all changes: git push origin master . 推送所有更改: git push origin master

To be able to use git with multiple accounts, I found this account here to be very useful. 为了能够在多个帐户中使用git ,我发现这里的帐户非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM