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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18695969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:02:28  来源:igfitidea点击:

Cannot push commits to a remote repository - GitHub

gitgithubgithub-for-mac

提问by Sriram

I have an Android project I was working on in Eclipse. 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. Subsequently, I made a couple more minor commits to the code and all went well.

我有一个在 Eclipse 中工作的 Android 项目。我在 github 上为自己创建了一个帐户,并使用 GitHub for Mac 客户端将项目中的代码推送到在线远程存储库。随后,我对代码进行了几次较小的提交,并且一切顺利。

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:
Sync Failed: Please commit all your changes before syncing.

现在代码发生了一些重大变化,当我尝试使用 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/masterfrom the command line. This resulted in 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.

为了解决这个问题,我尝试了以下方法:
1. 尝试git push origin/master从命令行使用。这导致project/info/refs not found: did you run git update-server-info on the server?
2. 我检查了存储库名称、位置等是否全部正确,并且确实如此。

My question(s):
1. There are a large number of .classfiles which show up in the Changes section. Why do they show up given that .class files are included in .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?

我的问题:
1..class更改部分中显示了大量文件。鉴于 .class 文件包含在 .class 文件中,为什么它们会出现.gitignore?既然已经出现了,还需要选择提交吗?
2. 上面的错误信息是什么意思,我该如何摆脱它?

EDIT 1:
After the following commands:
1. git ls-tree -r master | grep .class- this showed that .classfiles were also added to the repository.
2. git rm **/*.classto remove all .classfiles from the repository.
3. git commit -m "remove class files
4. git push origin masterresults in:

编辑 1:
在以下命令之后:
1. git ls-tree -r master | grep .class- 这表明.class文件也被添加到存储库中。
2.从存储库中git rm **/*.class删除所有.class文件。
3. git commit -m "remove class files
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 statuson 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. I am a newbie to git and have used only cvs before, so please dumb-down your answers, if possible.

我已经浏览了很多关于这个主题的主题,并查看了 SSH-keygen 之类的东西,但我认为这不是我问题的解决方案。我是 git 的新手,以前只使用过 cvs,所以如果可能的话,请把你的答案弄得一团糟。

My .gitignorefile:

我的.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

采纳答案by Sriram

The problem was that I was signed in to GitHub's Mac client using a personal ID. This personal ID was not registered as a collaborator on the project. Adding my personal account as a collaborator (an ugly work-around) solved the problem. I was able to commmit changes to the repository.

问题是我GitHub使用个人 ID登录了的 Mac 客户端。此个人 ID 未注册为项目的合作者。添加我的个人帐户作为合作者(一个丑陋的解决方法)解决了这个问题。我能够提交对存储库的更改。

Other suggestions which I found useful:
- Removing .classfiles from the repository.
To check if .classfiles were being tracked: git ls-tree -r master | grep .class
To remove them from the repo and commit: git rm **/*.classfollowed by git commit -m "your message goes here"
To push all changes: git push origin master.

我发现有用的其他建议:
-.class从存储库中删除文件。
检查.class文件是否被跟踪:git ls-tree -r master | grep .class
从 repo 中删除它们并提交:git rm **/*.class其次是git commit -m "your message goes here"
推送所有更改:git push origin master

To be able to use gitwith multiple accounts, I found this account hereto be very useful.

为了能够git与多个帐户一起使用,我发现这里的这个帐户非常有用。

回答by g19fanatic

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,用于告诉您的存储库与远程存储库的关系。

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? This SO questionshould shed some light.

您是否偶然更改了 github 存储库的名称?这个SO 问题应该说明一些问题

回答by Honril Awmos

It is possible that you have committed the .class files in the repository already. In which case git will keep tracking them even if you put *.class in the .gitignore file. Run git ls-tree -r master | grep .class. If that gives any output you have committed .class files. If so, try running git rm **/*.classand commit the change.

您可能已经提交了存储库中的 .class 文件。在这种情况下,即使您将 *.class 放在 .gitignore 文件中,git 也会继续跟踪它们。运行git ls-tree -r master | grep .class。如果这给出了您已提交的任何输出 .class 文件。如果是这样,请尝试运行git rm **/*.class并提交更改。

You are not supposed to run git push origin/masteryou need to specify a remote and then (optionally) a branch. Now git will try to parse origin/masteras a remote. Use git push origin masterinstead (use a space not a /). origin/masteris a branch that you should not be changing yourself anyway.

你不应该运行git push origin/master你需要指定一个远程然后(可选)一个分支。现在 git 将尝试解析origin/master为远程。使用git push origin master替代(用空间不是/)。origin/master是一个无论如何你都不应该改变自己的分支。

Besides you have *.class multiple times in your .gitignore. Multiple occurrences will not change the behavior of git.

此外,您的 .gitignore 中有多次 *.class。多次出现不会改变 git 的行为。

回答by BENARD Patrick

' git commit . ' will commit all your changes.

' git 提交。' 将提交您的所有更改。

Maybe you can try it... ( I'm not sure, just an idea )

也许你可以尝试一下......(我不确定,只是一个想法)