Git pull reverted commits in master?

删除回忆录丶 提交于 2019-12-05 13:42:37

The only way for git pull origin/aaron to do this is if he had a merge from master into aaron first, that discarded all of the changes on master (perhaps by using git merge -s ours master).

Go check the history. Are there any previous merges from master into aaron? And do they discard master's changes? If there are none, then the only explanation is he did not run git pull origin/aaron.

As for reinstating the changes, you could just back out his merge and re-create it yourself. That's going to modify history, but if you're ok with that, it's the easiest solution. If you're not ok with that, then it gets slightly more complicated. In that case, you'll want to create a temporary branch, back out his merge, and re-merge correctly. Then go back to master and run git read-tree tempbranch. This will update your index with the results of your temporary correct merge[1], and you can then commit this.

[1]: Note, this won't modify your working tree, so you'll want to follow this up with something like git checkout -- ..

asm

Given that all the changes occurred in the merge commit you're seeing what's known as an evil merge. man gitglossary defines it this way:

       evil merge
       An evil merge is a merge that introduces changes that do not appear in any
       parent.

There's an explanation of what this means in this answer. The important thing to know for you is that this isn't something that git will do by itself. Creating an evil merge requires human intervention in some way.

Where I've typically seen it happen is when someone does a merge and gets confused because of conflicts. For instance, one thing that could potentially have caused this is if aaron started his pull, got overwhelmed by conflicts, and decided that it was safe to solve the conflicts by copying his file(s) over top of the existing file(s). When he makes the merge commit after doing this you'll see exactly this.

As far as fixing it, I would do what Kevin Ballard suggested if you can. git -reset --hard the master branch back to how it looked before the merge and then redo the merge.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!