简体   繁体   English

Eclipse Git(EGit)-在与本地分支进行错误合并和提交之后,如何将本地主服务器恢复为远程主服务器

[英]Eclipse Git (EGit) - How to revert local master back to remote master after a foul merge & commit with a local branch

I have the following setup: 我有以下设置:

  • Remote origin/master (default branch) 远程原点/主节点(默认分支)

  • Locally, I got the master and created another branch - NewBranch. 在本地,我得到了管理员,并创建了另一个分支-NewBranch。

Someone in my team updated master on the remote. 我团队中的某人更新了遥控器上的主机。 I was able to pull in all the changes that they made. 我能够提取他们所做的所有更改。

However, while merging I had conflicts. 但是,合并时发生冲突。 Unintentionally, instead of updating NewBranch with the conflicted result, I have updated the local master with NewBranch (because master was the one that was currently checked out-or "active" in Eclipse). 我无意间没有用冲突的结果更新NewBranch ,而是用NewBranch更新了本地master(因为master是当前在Eclipse中签出或“活动”的master)。 Furthermore I committed this change (locally) to my local master branch... 此外,我将此更改(本地)提交给我的本地master分支...

I was able to switch to NewBranch and merge it with all the latest changes (so my Newbranch is perfectly the way I want it). 我能够切换到NewBranch并将其与所有最新更改合并(因此,我的Newbranch正是我想要的方式)。

Now, I'd like the master to point to the same version as remote master does. 现在,我希望主服务器指向与远程主服务器相同的版本。 So that in the future I have a clean merge between my NewBranch and the Master 这样以后我的NewBranch和Master之间就可以合并了

I've tried to "Reset" the master, but after performing a hard reset, the Hash Ids b/w the local master and remote master still do not match. 我试图“重置”主服务器,但是在执行硬重置后,本地主服务器和远程主服务器的哈希ID b / w仍然不匹配。

I also have References in my git eclipse and the reference of FETCH_HEAD is the one I'd like my master to revert to. 我的git eclipse中也有References,而FETCH_HEAD的引用是我希望我的主管理员恢复到的引用。

How can I do this using git in Eclipse? 如何在Eclipse中使用git做到这一点?

Thanks in advance 提前致谢

I am guessing you are asking these 2 questions? 我猜您在问这两个问题?

  1. Now, I'd like the master to point to the same version as remote master does 现在,我希望主服务器指向与远程主服务器相同的版本

If I'm right follow this, if you master should point to remote master 如果我是正确的,请遵循此步骤,如果您的主人应该指向远程主人

git pull origin master

If your NewBranch should point to remote master 如果您的NewBranch应该指向远程主机

git pull origin NewBranch
  1. I also have References in my git eclipse and the reference of FETCH_HEAD is the one I'd like my master to revert to. 我的git eclipse中也有References,而FETCH_HEAD的引用是我希望我的主管理员恢复到的引用。

Please right-click on project in your eclipse--->go to team----> check the git options 请在日食中右键单击项目--->进入团队---->检查git选项

在此处输入图片说明

These commands will help you to revert to a specific commit 这些命令将帮助您还原到特定的提交

git checkout master
git reset --hard e3f1e37
git push --force origin master
# Then to prove it (it won't print any diff)
git diff master..origin/master

Alternative 另类

Sometimes you may want to undo a whole commit with all changes. 有时您可能想撤消所有更改的整个提交。 Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. 无需手动进行所有更改,您只需告诉git还原一次提交即可,甚至不必是最后一次提交。 Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. 还原提交意味着创建一个新的提交,该新提交将撤消对该错误提交所做的所有更改。 Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it. 就像上面一样,错误的提交仍然存在,但是它不再影响当前的主数据库,也不会影响将来的所有提交。

git revert ~specificCommit

But remember this after git revert, if you want to go back, you need to read this Git revert be careful before you do it. 但是请记住,在git revert之后,如果要返回,则需要仔细阅读此Git revert,然后再进行操作。

git revert 45ae34 e34526a #created two revert commits

git revert HEAD~2..HEAD #by taking ranges, it will revert last 2 commits

git revert -m 1 <merge_commit_sha> #this basically reverts a merge commit

# To get just one, you could use `rebase -i` to squash them afterwards
# Or, you could do it manually (be sure to do this at top level of the repo)
# get your index and work tree into the desired state, without changing HEAD:
git checkout 34e2w34 .

git commit #commit here

Docs: git docs: undo merges 文档:git文档: 撤消合并

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

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