Git pull回复主人的提交? [英] Git pull reverted commits in master?

查看:128
本文介绍了Git pull回复主人的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一位我们称之为Aaron的同事被分配到一个网站的一部分作为一个长期项目。他创建了一个新的Git分支,名为 aaron 。他所有的改变都是在这个分支上进行的。在他工作的同时,我继续维护整个网站,并对 master 进行了修改。



最终,Aaron将他的分支合并到 master 中。这不知何故将合并时间与 aaron 之间的所有提交都还原为 master >分支最初创建。如果我输入 git show< hash of merge commit> ,我可以看到Aaron在他的分支上工作的每个文件的差异。那些差异显示了我所做的每一项改变的回归。如果Aaron将分支上的每个文件的内容手动复制到 master 并提交更改,它看起来就是这样。 (他没有这样做,我只是想说明日志显示的内容。)



据Aaron说,他没有做任何奇怪的事情。他说他只是跑了 git pull origin / aaron



这是什么原因造成的?是否可能 git pull origin aaron 会将所有更改恢复为 master



另外,是否有一种简单的方法可以在不恢复所有工作的情况下恢复对主人的更改?

编辑1: / strong>

master 中更改并在合并后还原的文件之一是 foo.txt的。所以我这样做了:

  git checkout aaron 
git log foo.txt

日志没有反映对 foo.txt 在创建 aaron 分支之后。我有点期待看到我的更改在日志中的 aaron 分支的某处反转,但我没有。那么,这是Aaron做了一些他声称已经完成的简单拉动的最后证明吗?

>

我曾经说过他输入了 origin / aaron ,但他实际上输入了 origin aaron 。我改变了它。



编辑3



,我选择通过重写历史来解决这个问题。我在这一点上确信这个问题是由错误地解决冲突的尝试造成的。

c $ c> git pull origin / aaron 这样做是因为他从 master aaron 首先放弃 master 上的所有更改(可能使用 git merge -s our master )。



查看历史记录。以前是否有从 master aaron 的任何合并?他们是否放弃 master 的更改?如果没有,那么唯一的解释是他没有运行 git pull origin / aaron



至于恢复更改,您可以退出合并并自行重新创建。这将修改历史记录,但如果你确定,那是最简单的解决方案。如果你不是这样,那么它会变得稍微复杂一些。在这种情况下,您需要创建一个临时分支,退出合并,然后正确重新合并。然后回到master并运行 git read-tree tempbranch 。这会使用临时正确合并的结果[1]更新您的索引,然后您可以提交它。



[1]:请注意,这不会修改你的工作树,所以你需要像 git checkout - 。


A colleague, whom we'll call Aaron, was assigned to renovate a section of a website as a long-term project. He created a new Git branch, called aaron. All his changes were made on this branch. While he was working, I continued to maintain the site as a whole, committing my changes to master.

Eventually, Aaron merged his branch into master. This somehow reverted all of the commits I'd made to master between the time of the merge and the time when the aaron branch was first created. If I type git show <hash of merge commit>, I can see diffs for every file I changed while Aaron was working on his branch. Those diffs show a reversion of every change I made. It looks the way it would if Aaron had manually copied the contents of each file on his branch into master and committed the changes. (He didn't do this. I'm just trying to illustrate what the log is showing.)

According to Aaron, he didn't do anything weird. He says he just ran git pull origin/aaron.

What could have caused this? Is it possible that git pull origin aaron would have reverted all my changes to master?

Also, is there an easy way to reinstate my changes to master without reverting all of his work?

EDIT 1:

One of the files that was changed in master and then reverted after merge was foo.txt. So I did this:

git checkout aaron
git log foo.txt

The log does not reflect any changes to foo.txt after the moment the aaron branch was created. I was sort of expecting to see a reversion of my changes somewhere in the log for the aaron branch, but I didn't. So, is this final proof that Aaron did something other than the simple pull that he claims to have done?

EDIT 2:

I had said he typed origin/aaron, but he actually typed origin aaron. I've changed it above.

EDIT 3

As per suggestions below, I chose to solve this by rewriting history. I am at this point convinced that the problem was caused by a misguided attempt to resolve conflicts.

解决方案

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 -- ..

这篇关于Git pull回复主人的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆