简体   繁体   English

Android Studio Git 推送被拒绝

[英]Android Studio Git Push Rejected

I'm trying to uploading my Android Project on github but I get this error when I try to push:我正在尝试在 github 上上传我的 Android 项目,但是当我尝试推送时出现此错误:

Push rejected: Push to origin/master was rejected

I made this steps:我做了这个步骤:

after push follow these,推后遵循这些,

VCS --> Git --> Branches VCS --> Git --> 分支

then select origin/master --> Rebase然后选择origin/master --> Rebase

after finish rebase successful message, you could able to push to remote directory.完成 rebase 成功消息后,您可以推送到远程目录。 Hope this helps you.希望这对你有帮助。

As suggested in the comments you should pull the changes first, if you are working on a new repository that could happened when you create your remote repo with a readme or a licence file.正如评论中所建议的,如果您正在使用自述文件或许可证文件创建远程存储库时可能发生的新存储库,则您应该先拉取更改。 To pull the changes from the user interface you should use, VCS > Git > Pull then select the master branch (depends)要从您应该使用的用户界面中提取更改,请VCS > Git > Pull然后选择主分支(取决于)

在此处输入图片说明

after that you can Git > Push without problem.之后,您可以毫无问题地进行Git > Push

Just go to the root directory of your project and follow below steps:只需转到项目的根目录并按照以下步骤操作:

  • Right Click-> Git Bash Here右键单击-> Git Bash 这里

  • Type git init (For initializing git).输入git init (用于初始化 git)。

  • Type git add -A (Get all files in the staging area).输入git add -A (获取暂存区中的所有文件)。

  • Type git commit -m "First Commit" (Commit Changes)输入git commit -m "First Commit" (Commit Changes)

  • Type git remote add origin https://your_git_url.git (Your repo URL)输入git remote add origin https://your_git_url.git (你的https://your_git_url.git URL)

  • Type git push -u origin master (master - Branch name)输入git push -u origin master (master - 分支名称)

    OR

  • Type git push -f origin master (master - Branch name) ( -f for Force push and make sure there are no changes in your branch to push code.)输入git push -f origin master (master - Branch name)( -f表示强制推送并确保你的分支中没有任何更改来推送代码。)

You can also make use of Git GUI client:您还可以使用 Git GUI 客户端:

  • Github Desktop for github users Download github用户的Github桌面下载
  • GitKracken for Windows, Mac and Linux Download (Free for public repositories)适用于 Windows、Mac 和 Linux 的 GitKracken下载(公共存储库免费)
  • SourceTree for Windows and Mac Download适用于 Windows 和 Mac 的 SourceTree下载

For Android Studio if your "Push" is rejected, go ahead and try this:对于 Android Studio,如果您的“推送”被拒绝,请继续尝试以下操作:

Try to Pull.(Origin/Master).Right after that:尝试拉。(起源/大师)。在那之后:

VCS-->Git-->Branches..-->Remote Branches(origin/master)-->Rebase Current onto Selected VCS-->Git-->Branches..-->远程分支(origin/master)-->Rebase Current on Selected

在此处输入图片说明

This will eradicate all your contradicting configurations.这将消除您所有的矛盾配置。

Try this试试这个

This type of error was also coming in my project because i have create a new project and paste my old config and some classes file in new project.这种类型的错误也出现在我的项目中,因为我创建了一个新项目并将旧配置和一些类文件粘贴到新项目中。

I have pushed the code by creating new branch我通过创建新分支来推送代码

Go to VCS->Git->Branches->New BranchVCS->Git->Branches->New Branch

If none of the above solution works then you can check this out..如果上述解决方案都不起作用,那么您可以检查一下..

  1. Log in to the GitHub account and go the settings.登录 GitHub 帐户并进行设置。
  2. In settings open Emails section and check whether it is public or private.在设置中打开电子邮件部分并检查它是公共的还是私人的。
  3. If it is public then other solution will work out finely and if your email is private then declare it public.如果它是公开的,那么其他解决方案会很好地工作,如果您的电子邮件是私人的,则将其声明为公开。

Because of the private email you aren't able to push the files in the repository from your IDE.由于私人电子邮件,您无法从 IDE 推送存储库中的文件。 So, make it public那就公开吧

Another Solution.!!另一个解决方案.!!

The unversioned code is not versioned, the changes are committed but don't push.未版本化的代码没有版本化,更改已提交但不推送。 Following are the steps to make the files versioned.以下是使文件版本化的步骤。

  1. Open the project tab(must be in the left side toolbar, if not then press 'Alt + F1')打开项目选项卡(必须在左侧工具栏中,如果没有,请按“Alt + F1”)
  2. At the top, there is a dropdown with 'Android', open the dropdown and select the 'Project'在顶部,有一个带有“Android”的下拉菜单,打开下拉菜单并选择“项目”
  3. In the list shown, right click your project folder在显示的列表中,右键单击您的项目文件夹
  4. There must be a option of 'Git', select it必须有'Git'的选项,选择它
  5. Choose the 'Add' option.选择“添加”选项。 And there it is!.它就在那里!。 Now simply try to commit and push operation as usual.现在只需像往常一样尝试提交和推送操作。

**NOTE :**You've to add files everytime using the above steps to upload the files successfully.!! **注意:**您必须每次使用上述步骤添加文件才能成功上传文件。!!

Thank you folks :)谢谢各位:)

I had this same problem.我有同样的问题。 I finally tried it from the command line and and received this message:我终于从命令行尝试了它并收到了这条消息:

    remote: error: GH007: Your push would publish a private email address.
    remote: You can make your email public or disable this protection by visiting: 
    remote: http://github.com/settings/emails

There you should see two checkboxes.在那里你应该看到两个复选框。 You will need to uncheck one of them.您需要取消选中其中之一。

  • Keep my email address private将我的电子邮件地址保密
  • Block command line pushes that expose my email阻止暴露我的电子邮件的命令行推送

I had the same problem, just solve it by doing this:-我遇到了同样的问题,只需通过这样做来解决它:-

Go to Github account settings转到 Github 帐户设置

(1) (1)

在此处输入图片说明

(2) (2) 在此处输入图片说明

I had the same issue when I Fork from my another github account and clone it in Android Studio, I changed some file and commit(success) and pushed and that is rejected.当我从另一个 github 帐户分叉并在 Android Studio 中克隆它时,我遇到了同样的问题,我更改了一些文件并提交(成功)并推送并被拒绝。

The problem was, I have logged into GitHub in Android Studio with my other account, not the one I'm fork the project.问题是,我使用另一个帐户登录了 Android Studio 中的 GitHub,而不是我为该项目创建的帐户。 Check out your's from:从以下位置查看您的:

File -> Setting -> Version Control -> GitHub文件 -> 设置 -> 版本控制 -> GitHub

If account information is not match with the repo cloned account, change it.如果账户信息与 repo 克隆账户不匹配,请更改它。

Then you can Push without a problem.然后你可以毫无问题地推送

We can get around this "limitation" by editing the .git/config on the destination server.我们可以通过编辑目标服务器上的 .git/config 来解决这个“限制”。 Add the following to allow a git repository to be pushed to even if it is "checked out":添加以下内容以允许将 git 存储库推送到,即使它已“签出”:

[receive]
denyCurrentBranch = warn

or

[receive]
denyCurrentBranch = false

如果您是第一次推送,请从 git 中删除存储库,然后在 Android Studio 3 中的 Git 上再次共享该项目

This is the case when you make a repository with a readme file default and so you can either pull first or make a new repository without a readme file and dont forget to change the repo URL.当您使用自述文件默认存储库时就是这种情况,因此您可以先拉取或创建没有自述文件的新存储库,并且不要忘记更改存储库 URL。 Hope it helps.希望它有帮助。 Cheers.干杯。

When I encountered the same error in Android Studio;当我在 Android Studio 中遇到同样的错误时; I just simply renamed my remote name and it fixed the error.我只是简单地重命名了我的远程名称并修复了错误。 Steps which I followed are:我遵循的步骤是:

  1. Right click on project name and go to Repository option.右键单击项目名称并转到存储库选项。
  2. Then select Remotes.然后选择遥控器。
  3. Then you will be asked to Define Remote by providing a name of the remote and URL of your GitHub repository.然后,系统会要求您通过提供远程名称和 GitHub 存储库的 URL 来定义远程。 Just change the name according to your choice if 'origin' is already filled and then fill the URL of your GitHub repository.如果 'origin' 已经填写,只需根据您的选择更改名称,然后填写您的 GitHub 存储库的 URL。

I am giving clear note here skip steps you already done..我在这里给出明确的说明跳过你已经完成的步骤..

first create new repository in github.首先在github中创建新的存储库。 (dont close the tab until work done) (在完成工作之前不要关闭选项卡)

then you have to check whether you are log into your github account in android studio.然后你必须检查你是否在android studio中登录了你的github帐户。 if not you can log in setting-->Version Control --> github.如果没有,您可以登录设置-->版本控制--> github。

Then go to VCS -> Import into Version Control.然后转到 VCS -> 导入到版本控制。

now in android studio project tab change it from android to project .Android to Project.现在在 android studio project 选项卡中将其从 android 更改为 project .Android 到 Project。

step 3: then Right click on your project select git then +add .第 3 步:然后右键单击您的项目选择 git 然后+add again Right click -> commit and again Right click --> git--> repository--> push .再次右键单击->提交,然后再次右键单击--> git--> repository--> push in the new window select origin ->master then push.. if you already do this part and get the error in here do this.(i think this is the first time you try to add your project to github and github repo is empty.)在新窗口中选择 origin ->master 然后 push .. 如果你已经做了这部分并在这里得到错误,请执行此操作。(我认为这是你第一次尝试将你的项目添加到 github 并且 github repo 是空的。 )

goto terminal (bottom of the ide) remove origin using this command. goto 终端(ide 的底部)使用此命令删除原点。 git remote rm origin

now do step 3 again.现在再次执行第 3 步。 after that you will asked to enter github repository url.之后,您将要求输入 github 存储库 url。 whenever you add url make sure to add .git .每当您添加 url 时,请确保添加.git at the end of the url .在 url 的末尾

like this.像这样。 https://github.com/ /xylophoneApp. https://github.com/ /xylophoneApp。 git混帐

for anyone maybe Suffers with this issue like me, the entire problem was with executionHistory.bin file, and don't ask me why because I don't know at all.对于任何可能像我一样遇到这个问题的人来说,整个问题都出在executionHistory.bin文件上,不要问我为什么,因为我根本不知道。

just create commit without this file and push it, this was the solution for my issue.只需创建没有此文件的提交并推送它,这是我的问题的解决方案。

Hope this help someone.希望这有助于某人。

In my case initially, I had created a new repository with a Readme file.That's causing the issue.就我而言,最初,我创建了一个带有自述文件的新存储库。这就是导致问题的原因。 Next time when I create new repo without the Readme file, everything works fine下次当我创建没有自述文件的新仓库时,一切正常

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

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