简体   繁体   English

被拒绝的主人 - >主人(非快进)

[英]rejected master -> master (non-fast-forward)

I'm trying to push my project (all files in a new repository).我正在尝试推送我的项目(新存储库中的所有文件)。 I follow the steps but when I push with git push -u origin master I get this error:我按照这些步骤操作,但是当我使用git push -u origin master推送时,出现此错误:

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:asantoya/projectnewbies.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

I got this error many times and can't figure out what to do.我多次遇到此错误,不知道该怎么办。

NOTICE: This is never a recommended use of git.注意:这绝不是 git 的推荐用法。 This will overwrite changes on the remote.这将覆盖遥控器上的更改。 Only do this if you know 100% that your local changes should be pushed to the remote master.仅当您 100% 知道您的本地更改应该推送到远程主服务器时才这样做。

⚠️ Try this: git push -f origin master ⚠️ 试试这个: git push -f origin master

As the error message says: git pull before you try to git push .正如错误消息所说: git pull before you try to git push Apparently your local branch is out of sync with your tracking branch.显然,您的本地分支与您的跟踪分支不同步。

Depending on project rules and your workflow you might also want to use git pull --rebase .根据项目规则和您的工作流程,您可能还想使用git pull --rebase

这个命令对我很有效

git push -f origin master
git push -f origin master

使用蛮力 ;-) 很可能您正在尝试添加在 git 上创建 repo 之前创建的本地文件夹。

I've just received this error.我刚刚收到此错误。

I created a github repository after creating my local git repository so I needed to accept the changes into local before pushing to github.我在创建本地 git 存储库后创建了一个 github 存储库,因此我需要在推送到 github 之前接受对本地的更改。 In this case the only change was the readme file created as optional step when creating github repository.在这种情况下,唯一的变化是创建 github 存储库时作为可选步骤创建的自述文件。

git pull https://github.com/*username*/*repository*.git master

repository URL is got from here on project github page :存储库 URL 来自项目 github 页面上的这里:

在此处输入图片说明

I then re-initialised (this may not be needed)然后我重新初始化(这可能不需要)

git init
git add .
git commit -m "update"

Then push :然后推:

git push

If git pull does not help, then probably you have pushed your changes (A) and after that had used git commit --amend to add some more changes (B).如果git pull没有帮助,那么您可能已经推送了更改(A),然后使用git commit --amend添加了更多更改(B)。 Therefore, git thinks that you can lose the history - it interprets B as a different commit despite it contains all changes from A.因此,git 认为您可能会丢失历史记录 - 尽管它包含来自 A 的所有更改,但它将 B 解释为不同的提交。

             B
            /
        ---X---A

If nobody changes the repo after A , then you can do git push --force .如果在A之后没有人更改 repo,那么您可以执行git push --force

However, if there are changes after A from other person:但是,如果其他人在A之后发生了变化:

             B
            /
        ---X---A---C

then you must rebase that persons changes from A to B ( C -> D ).那么你必须重新确定人从AB ( C -> D ) 的变化。

             B---D
            /
        ---X---A---C

or fix the problem manually.或手动修复问题。 I didn't think how to do that yet.我还没想好怎么做。

i had created new repo in github and i had the same problem, but it also had problem while pulling, so this worked for me.我在 github 中创建了新的 repo 并且我遇到了同样的问题,但是在拉动时它也有问题,所以这对我有用。

but this is not advised in repos that already have many codes as this could mess up everything但是在已经有很多代码的回购中不建议这样做,因为这可能会弄乱一切

git push origin master --force

WARNING:警告:

Going for a ' git pull ' is not ALWAYS a solution, so be carefull.寻求“ git pull ”并不总是解决方案,所以要小心。 You may face this problem (the one that is mentioned in the Q) if you have intentionally changed your repository history.如果您有意更改了存储库历史记录,您可能会遇到这个问题(Q 中提到的那个)。 In that case, git is confusing your history changes with new changes in your remote repo.在这种情况下,git 会将您的历史更改与远程存储库中的新更改混淆。 So, you should go for a git push --force , because calling git pull will undo all of the changes you made to your history, intentionally.因此,您应该使用git push --force ,因为调用git pull会有意撤消您对历史记录所做的所有更改。

use this command:使用这个命令:

git pull --allow-unrelated-histories <nick name of repository> <branch name>

like:喜欢:

git pull --allow-unrelated-histories origin master

this error occurs when projects don't have any common ancestor.当项目没有任何共同的祖先时会发生此错误。

This is because you did some changes in your master so the project ask you to pull first.这是因为您在 master 中做了一些更改,因此项目要求您先拉取。 If you want to push it anyway you can use brute force by typing this:如果您无论如何都想推动它,您可以通过键入以下内容使用蛮力:

git push -f origin master

Remember to first commit your changes:请记住首先提交您的更改:

git add .
git commit -m "Your commit message"

Try this command: "git pull origin master"试试这个命令:“git pull origin master”

It worked for me.它对我有用。

Check this link: https://help.github.com/articles/dealing-with-non-fast-forward-errors检查此链接: https : //help.github.com/articles/dealing-with-non-fast-forward-errors

You need to do你需要做

git branch

if the output is something like:如果输出是这样的:

* (no branch)
master

then do然后做

git checkout master

Make sure you do not have any pending commits as checking out will lose all non-committed changes.确保您没有任何挂起的提交,因为签出将丢失所有未提交的更改。

! [rejected] master -> master (non-fast-forward) [拒绝] master -> master(非快进)

Don't panic, this is extremely easy to fix.不要惊慌,这是非常容易修复的。 All you have to do is issue a pull and your branch will be fast-forward:您所要做的就是发出拉动,您的分支将快进:

$ git pull myrepo master $ git pull myrepo master

Then retry your push and everything should be fine:然后重试你的推送,一切都应该没问题:

$ git push github master $ git push github master

This happened to me when I was on develop branch and my master branch is not with latest update.当我在开发分支并且我的主分支没有最新更新时,这发生在我身上。

So when I tried to git push from develop branch I had that error.所以当我尝试从开发分支 git push 时,我遇到了那个错误。

I fixed it by switching to master branch, git pull, then go back to develop branch and git push.我通过切换到 master 分支,git pull 来修复它,然后返回到开发分支和 git push。

$ git fetch && git checkout master
$ git pull
$ git fetch && git checkout develop
$ git push

I had this problem on a development machine.我在开发机器上遇到了这个问题。 The dev branch was pushing fine but the the master branch gave me (while git push ing when being on the dev branch): dev分支推得很好,但master分支给了我(当在dev分支上时git push ):

! [rejected]        master -> master (non-fast-forward)

So I tried:所以我试过:

git checkout master
git pull

Which gave me:这给了我:

You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either.

I found out the master branch was missing from .git/config and added:我发现.git/config缺少 master 分支并添加了:

[branch "master"]
    remote = origin
    merge = refs/heads/master

Afterwards git push also worked fine on the dev branch.之后git pushdev分支上也运行良好。

My Remote was not in sync with the local so this worked for me我的遥控器与本地不同步,所以这对我有用

git pull --rebase

and make sure when you do git pull again it should say Already up to date and now you are ready to push to origin并确保当你再次执行git pull时,它应该说已经是最新的,现在你已经准备好推送到原点了

assuming you have already git remote add origin remote repository URL假设你已经有git remote add origin remote repository URL

do

`git push origin master`  

The Screenshot says it all截图说明了一切在此处输入图片说明

Alternatively you can do this或者你可以这样做

  1. git stash (stores uncommited work temporarily) git stash(临时存储未提交的工作)
  2. git pull (make your local and remote in sync) git pull(使您的本地和远程同步)
  3. git stash pop (get back you uncommited changes ) git stash pop(取回未提交的更改)
  4. git push

I had same as issue.我有同样的问题。 I use Git Totoise.我使用 Git Totoise。 Just Right Click ->TotoiseGit -> Clean Up .只需右键单击 -> TotoiseGit -> 清理。 Now you can push to Github It worked fine with me :D现在你可以推送到 Github 它对我很好:D

This is because you have made conflicting changes to its master.这是因为您对其 master 进行了相互冲突的更改。 And your repository server is not able to tell you that with these words, so it gives this error because it is not a matter of him deal with these conflicts for you, so he asks you to do it by itself.而你的存储库服务器无法用这些话告诉你,所以它会给出这个错误,因为他为你处理这些冲突不是他的事情,所以他要求你自己做。 As ?作为 ?

1- git pull This will merge your code from your repository to your code of your site master. 1- git pull这会将您的代码从您的存储库合并到您的站点主代码。 So conflicts are shown.所以显示冲突。

2- treat these manualemente conflicts. 2- 处理这些手册冲突。

3- 3-

git push origin master

And presto, your problem has been resolved.而且很快,您的问题已经解决。

This may also be caused due to some name error caused while giving name to the Repo.这也可能是由于在为 Repo 命名时导致的一些名称错误造成的。 If any of the above answers haven't worked .This worked for me:如果上述任何答案都不起作用。这对我有用:

Delete that repo and create a new one and try the following commands again:删除该存储库并创建一个新存储库,然后再次尝试以下命令:

cd 'Local Directory Path'
git remote add origin *your_git_name.git*
git push -u origin master

if add origin shows already exists use this instead:如果添加原点显示已经存在,请改用它:

git remote set-url origin *your_git_name.git*

The only i was able to resolve this issue was to delete the local and git repo and create the same again at both ends.我唯一能够解决这个问题的是删除本地和 git repo 并在两端再次创建相同的。 Works fine for now.目前工作正常。

如果有人在尝试推送到 heroku 时遇到此错误,则只需将 'origin' 替换为 'heroku',如下所示: git push -f heroku master

试试这个,在我的情况下它有效

git rebase --abort

I also got the same error but I solved it easily by fetching its URLs as我也遇到了同样的错误,但我通过获取它的 URL 轻松解决了它

git fetch origin Your repository origin

then simply applying the command然后简单地应用命令

git push -f origin master

You will get a good result你会得到一个好的结果

This means that your remote git repository is configured with denyNonFastforwards = true .这意味着您的远程 git 存储库配置为denyNonFastforwards = true Although dangerous, sometimes you might really need to overwrite the git history (eg after running bfg --strip-blobs-bigger-than 100M ) thus you can temporarily modify that setting to false ( denyNonFastforwards = true , see it in your-repository.git/config ) then forcibly push (ie git push -f ).尽管很危险,但有时您可能确实需要覆盖 git 历史记录(例如,在运行bfg --strip-blobs-bigger-than 100M之后),因此您可以暂时将该设置修改为falsedenyNonFastforwards = true ,请在your-repository.git/config )然后强制推送(即git push -f )。

Sometimes, Git can't make your change to a remote repository without losing commits.In simple words,this may happen because your commit was lost or if someone else is trying to push to the same branch as you.有时,Git 无法在不丢失提交的情况下对远程存储库进行更改。简而言之,这可能是因为您的提交丢失或者其他人试图推送到与您相同的分支。 So to fix this, first make a pull request所以要解决这个问题,首先提出一个拉取请求

$ git pull origin YOUR_BRANCH_NAME

Or或者

$ git pull --rebase origin master

I solved this problem with Firstly of all:我首先解决了这个问题:

--Steps-- - 脚步 -

git add * git 添加 *

git fetch git 获取

git pull origin main --allow-unrelated-histories or git pull --rebase <your_reponame> <your_branch> git pull origin main --allow-unrelated-histories 或 git pull --rebase <your_reponame> <your_branch>

git push -u "" main or git pull origin [branch] git push -u "" main 或 git pull origin [branch]

为我工作

git push --force origin master

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

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