Git 非快进更新被拒绝 合并远程更改

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12236854/
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-10 14:30:42  来源:igfitidea点击:

Git non-fast-forward updates were rejected Merge the remote changes

gitgithub

提问by Tampa

How do I resolve this issue? I am trying to commit but I get the below error.

我该如何解决这个问题?我正在尝试提交,但出现以下错误。

git push origin monty_svm_dev

git push origin monty_svm_dev

To [email protected]:  ! [rejected]        monty_svm_dev -> monty_svm_dev
(non-fast-forward) error: failed to push some refs to
'[email protected]:/mygit.git' To prevent you from losing history,
non-fast-forward updates were rejected Merge the remote changes before
pushing again.  See the 'Note about fast-forwards' section of 'git
push --help' for details. root@li409-202:~/mypath#

回答by Michael Durrant

do git pull origin monty_svm_devfirst

git pull origin monty_svm_dev第一

What has happened is that the remote has more recent changes than your branch.

发生的情况是遥控器的更改比您的分支更新的要多。

So before you can pushyour changes, you need to get and merge the changes on the remote first.

因此,在您进行push更改之前,您需要先获取并合并遥控器上的更改。

You can do this either by doing a git checkout your_branch, then:

您可以通过执行 a 来做到这一点git checkout your_branch,然后:

git fetch origin your_branchand then a
git merge your_branch

git fetch origin your_branch然后一个
git merge your_branch

or

或者

git pull origin your_branch # fetch and merge in one operation

Where your branch is master, or your branch name (seems to be monty_svm_devin your case I think)

您的分支是 master 或分支名称的位置(monty_svm_dev我认为似乎是您的情况)

Once this is done (and any conflicts resolved) you can do a git push origin monty_svm_dev

完成此操作(并解决任何冲突)后,您可以执行 git push origin monty_svm_dev

回答by Bijendra

It basically because when you

这基本上是因为当你

git pull

from a branch , two operations take place fetch and merge. Now if your local has some changes then git will not allow you to push it before you commit your changes.

从一个分支,两个操作发生获取和合并。现在,如果您的本地有一些更改,那么 git 将不允许您在提交更改之前推送它。

Also this issue appears if the remote has changes which are still not pulled in local and merged, so you need to take a pull again and then push it. Do reply if it doen't solve the issue

如果远程仍然没有在本地拉取和合并的更改,也会出现此问题,因此您需要再次拉取然后推送它。如果没有解决问题请回复

回答by Dave

Do a Git pull. Then it will bring recent code changes in remote branch into your local. then you are able to push your changes.

做一个 Git 拉取。然后它将远程分支中最近的代码更改带入您的本地。然后您就可以推送您的更改。

回答by Nirmal

This issue arises when the user forgets to issue git pushcommand after git commitcommand. When using git, please always make sure the basic steps.

当用户忘记发出一个又一个git push命令时,就会出现这个问题git commit。使用 git 时,请务必确保基本步骤。

In an ideal cycle while working with git, always check the following git commands were used sequentially in the following order:

在使用 git 的理想循环中,始终检查以下 git 命令是否按以下顺序依次使用:

git pull
git add
git commit
git push

I personally avoid majority of the issues posted about git on stack, because I always tally my git command acitivites to the above sequence.

我个人避免在堆栈上发布的大多数关于 git 的问题,因为我总是将我的 git 命令活动记录到上述序列中。

I created an acronym to make sure I don't forget, I am hopoing the same can be useful to the reader which is:

我创建了一个首字母缩略词以确保我不会忘记,我希望它对读者有用,即:

pacp (read it as: pack push where (p=git push, a=git add, ck=git commit, push=git push).

pacp(读作:pack push where (p=git​​ push, a=git add, ck=git commit, push=git push)。

My way to memorise the git push, add, commit, pull is:

我记住 git push、add、commit、pull 的方法是:

get pack push (meaning: git the pack and then push).

get pack push(意思是:git the pack然后push)。

In summary remember to "git" the pack and then "push".

总而言之,记得先“git”打包,然后“push”。

Resolving the issues: I would like to add my most used recovery git commands that are:

解决问题:我想添加我最常用的恢复 git 命令,它们是:

git checkout -- path/to/file/fileName.something #undo changes in file

The above undoes the changes in a file...similar can be applied for multiple files using * for file name, similarly can be applied to multiple directories separated by space.

以上撤消了文件中的更改...类似的可以应用于多个文件,使用 * 作为文件名,同样可以应用于多个以空格分隔的目录。

git reset filename.txt 

The above removes the file from stage...after this command we can safely do git commit and git will only commit those files we are in stage which means the file "filname.txt" won't get committed)

上面从 stage 中删除了文件......在这个命令之后我们可以安全地执行 git commit 并且 git 只会提交我们在 stage 中的那些文件,这意味着文件“filname.txt”不会被提交)

git pull origin your_intended_branch

Changes are merged with the latest from your_intended_branch this basically merges the change which you committed but did not push. Once all goes fine, simply do the push:

更改与来自 your_intended_branch 的最新内容合并,这基本上合并了您提交但未推送的更改。一旦一切顺利,只需执行推送:

git push