eclipse Egit 拒绝非快进
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19474186/
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
Egit rejected non-fast-forward
提问by Jay
I am getting this message while pushing to github repository. Can you tell me step by step procedure to fix it? I pushed only once and it was successful. But, when I updated a project and tried to push my second commit, it shows "master rejected non-fast-forward" and does not allow me to push. Please explain the procedure.
我在推送到 github 存储库时收到此消息。你能告诉我一步一步的程序来修复它吗?我只推了一次就成功了。但是,当我更新一个项目并尝试推送我的第二次提交时,它显示“主拒绝非快进”并且不允许我推送。请说明程序。
回答by Robert Bender
I had this same problem and I was able to fix it. afk5min was right, the problem is the branch that you pulled code from has since changed on the remote repository. Per the standard git practices(http://git-scm.com/book/en/Git-Basics-Working-with-Remotes), you need to (now) merge those changes at the remote repository into your local changes before you can commit. This makes sense, this forces you to take other's changes and merge them into your code, ensuring that your code continues to function with the other changes in place.
我有同样的问题,我能够解决它。afk5min 是对的,问题是您从中提取代码的分支在远程存储库上发生了更改。根据标准的 git 实践(http://git-scm.com/book/en/Git-Basics-Working-with-Remotes),您需要(现在)将远程存储库中的这些更改合并到您的本地更改之前可以提交。这是有道理的,这迫使您接受其他人的更改并将它们合并到您的代码中,确保您的代码在其他更改就位的情况下继续运行。
Anyway, on to the steps.
无论如何,进入步骤。
Configure the 'fetch' to fetch the branch you originally pulled from.
Fetch the remote branch.
Merge that remote branch onto your local branch.
Commit the (merge) change in your local repo.
Push the change to the remote repo.
配置 'fetch' 以获取您最初从中提取的分支。
获取远程分支。
将该远程分支合并到您的本地分支。
在您的本地存储库中提交(合并)更改。
将更改推送到远程存储库。
In detail...
详细...
In eclipse, open the view 'Git Repositories'.
Ensure you see your local repository and can see the remote repository as a subfolder. In my version, it's called Remotes, and then I can see the remote project within that.
Look for the green arrow pointing to the left, this is the 'fetch' arrow. Right click and select 'Configure Fetch'.
You should see the URI, ensure that it points to the remote repository.
Look in the ref mappings section of the pop-up. Mine was empty. This will indicate which remote references you want to fetch. Click 'Add'.
Type in the branch name you need to fetch from the remote repository. Mine was 'master' (btw, a dropdown here would be great!!, for now, you have to type it). Continue through the pop-up, eventually clicking 'Finish'.
Click 'Save and Fetch'. This will fetch that remote reference.
Look in the 'Branches' folder of your local repository. You should now see that remote branch in the remote folder. Again, I see 'master'.
Right-Click on the local branch in the 'Local' folder of 'Branches', which is named 'master'. Select 'Merge', and then select the remote branch, which is named 'origin/master'.
Process through the merge.
Commit any changes to your local repository.
Push your changes to the remote repository.
Go have a tasty beverage, congratulating yourself. Take the rest of the day off.
在 Eclipse 中,打开视图“Git Repositories”。
确保您可以看到本地存储库,并且可以将远程存储库视为子文件夹。在我的版本中,它称为 Remotes,然后我可以在其中看到远程项目。
寻找指向左侧的绿色箭头,这是“获取”箭头。右键单击并选择“配置提取”。
您应该会看到 URI,确保它指向远程存储库。
查看弹出窗口的 ref mappings 部分。我的是空的。这将指示您要获取哪些远程引用。点击“添加”。
输入您需要从远程存储库中获取的分支名称。我的是“大师”(顺便说一句,这里的下拉菜单会很棒!!,现在,你必须输入它)。继续弹出窗口,最终单击“完成”。
单击“保存并获取”。这将获取该远程引用。
查看本地存储库的“分支”文件夹。您现在应该在远程文件夹中看到该远程分支。再一次,我看到了“主人”。
右键单击“Branches”的“Local”文件夹中名为“master”的本地分支。选择“合并”,然后选择名为“origin/master”的远程分支。
通过合并处理。
提交对本地存储库的任何更改。
将您的更改推送到远程存储库。
去喝一杯美味的饮料,祝贺自己。休息一天。
回答by BSeitkazin
In my case I chose the Force Update
checkbox while pushing. It worked like a charm.
在我的情况下,我Force Update
在推动时选择了复选框。它就像一个魅力。
回答by afk5min
In the meantime (while you were updating your project), other commits have been made to the 'master' branch. Therefore, you must pull those changes first to be able to push your changes.
与此同时(当你更新你的项目时),其他提交已经提交到“master”分支。因此,您必须首先拉取这些更改才能推送您的更改。
回答by Yogesh Manware
Applicable for Eclipse Luna + Eclipse Git 3.6.1
适用于 Eclipse Luna + Eclipse Git 3.6.1
I,
一世,
- cloned git repository
- made some changes in source code
- staged changes from Git Staging View
- finally, commit and Push!
- 克隆的 git 存储库
- 对源代码进行了一些更改
- Git 暂存视图中的暂存更改
- 最后,提交并推送!
And I faced this issue with EGit and here is how I fixed it..
我在 EGit 中遇到了这个问题,这是我修复它的方法。
Yes, someone committed the changes before I commit my changes. So the changes are rejected.
After this error, the changes gets actually committed to local repository.
I did not want to just Pull
the changes because I wanted to maintain linear history
as pointed out in - In what cases could `git pull` be harmful?
是的,有人在我提交更改之前提交了更改。因此拒绝更改。在此错误之后,更改实际上已提交到本地存储库。我不想只是Pull
更改,因为我想维护linear history
-在什么情况下`git pull`会有害?
So, I executed following steps
所以,我执行了以下步骤
- from Git Repository perspective, right click on the concerned Git
project - select
Fetch from Upstream
- it fetches remote updates (refs and objects) but no updates are made locally. for more info refer What is the difference between 'git pull' and 'git fetch'? - select
Rebase...
- this open a popup, click onPreserve merges during rebase
see why
What exactly does git's "rebase --preserve-merges" do (and why?) - click on
Rebase button
- if there is/are a
conflict(s)
, go to step 6 else step 11 - a
Rebase Result
popup would appear, just click onOK
file comparator
would open up, you need to modifyleft side file
.- once you are done with merging changes correctly, goto
Git Staging
view stage the changes
. i.e.add to index
- on the same view, click on
Rebase
->Continue
. repeat 7 to 10 until all conflicts are resolved. - from
History
view, select your commit row and selectPush Commit
- select
Rebase Commits of local.......
checkbox and click next. refer why - Git: rebase onto development branch from upstream - click on
Finish
- 从 Git Repository 的角度,右键单击相关的 Git
项目 - select
Fetch from Upstream
- 它获取远程更新(引用和对象),但不会在本地进行更新。有关更多信息,请参阅“git pull”和“git fetch”之间的区别是什么? - 选择
Rebase...
- 这会打开一个弹出窗口,点击Preserve merges during rebase
查看为什么
git 的“rebase --preserve-merges”究竟做了什么(以及为什么?) - 点击
Rebase button
- 如果有
conflict(s)
,则转到第 6 步,否则转到第 11 步 Rebase Result
将出现一个弹出窗口,只需单击OK
file comparator
会打开,你需要修改left side file
.- 正确完成合并更改后,转到
Git Staging
查看 stage the changes
. IEadd to index
- 在同一视图中,单击
Rebase
->Continue
。重复 7 到 10,直到解决所有冲突。 - 从
History
视图中,选择您的提交行并选择Push Commit
- 选择
Rebase Commits of local.......
复选框并单击下一步。参考原因 - Git:从上游重新定位到开发分支 - 点击
Finish
Note:if you have multiple local repository commits, you need to squash them in one commit to avoid multiple merges.
注意:如果您有多个本地存储库提交,则需要在一次提交中压缩它们以避免多次合并。
回答by Vineela Thonupunuri
ConfigureAfter pushing the code when you get a rejected message, click on configure and click Add spec as shown in this picture
配置在收到拒绝消息时推送代码后,单击配置并单击添加规范,如图所示
Drop down and click on the ref/heads/yourbranchname and click on Add Spec again
下拉并单击 ref/heads/yourbranchname,然后再次单击 Add Spec
Make sure you select the force update
回答by dafali
Open git view :
打开 git 视图:
1- select your project and choose merge 2- Select remote tracking 3- click ok
1- 选择您的项目并选择合并 2- 选择远程跟踪 3- 单击确定
Git will merge the remote branch with local repository
Git 会将远程分支与本地存储库合并
4- then push
4-然后推
回答by Pushkin
This error means that remote repository has had other commits and has paced ahead of your local branch.
I try doing a git pull followed by a git push. If their are No conflicting changes, git pull gets the latest code to my local branch while keeping my changes intact.
Then a git push pushes my changes to the master branch.
这个错误意味着远程存储库有其他提交并且比你的本地分支提前。
我尝试先执行 git pull,然后再执行 git push。如果它们没有发生冲突的更改,git pull 会将最新代码获取到我的本地分支,同时保持我的更改完好无损。
然后 git push 将我的更改推送到主分支。
回答by Mighty Elemental
I have found that you must be on the latest commit of the git. So these are the steps to take: 1) make sure you have not been working on the same files, otherwise you will run into a DITY_WORK_TREE error. 2) pull the latest changes. 3) commit your updates.
我发现您必须使用 git 的最新提交。所以这些是要采取的步骤:1)确保您没有处理相同的文件,否则您将遇到 DITY_WORK_TREE 错误。2) 拉取最新的变化。3) 提交您的更新。
Hope this helps.
希望这可以帮助。
回答by adrian filipescu
- Go in Github an create a repo for your new code.
- Use the new https or ssh url in Eclise when you are doing the push to upstream;
- 进入 Github,为你的新代码创建一个 repo。
- 向上游推送时,在 Eclise 中使用新的 https 或 ssh url;