我有一个git仓库,有2个分支:master和test。

主分支和测试分支之间存在差异。

两个分支都提交了所有更改。

如果我这样做:

git checkout master
git diff test

屏幕上会出现一个充满变化的屏幕,显示不同之处。我想合并测试分支中的更改,这样做:

git merge test

但是得到的信息是"Already - updated "

但是,检查每个不同分支下的文件可以清楚地显示出差异。

这里的问题是什么,我如何解决它?


当前回答

这种情况发生在我身上,因为GIT奇怪地认为本地分支与远程分支不同。 这在分支图中可见:它显示了两个不同的分支:remotes/origin/branch_name和branch_name。

解决方案是简单地删除本地回购并从远程重新克隆它。这样GIT就会理解remotes/origin/branch_name>和branch_name确实是相同的,并且我可以发出GIT合并branch_name。

rm <my_repo>
git clone <my_repo>
cd <my_repo>
git checkout <branch_name>
git pull
git checkout master
git merge <branch_name>

其他回答

同样的事情也发生在我身上。 但是这个场景有点不同,我有一个master分支,我从它中分离出release_1(比如说)。 在release_1分支中做了一些更改,并将其合并到origin中。然后我在远程服务器上使用ssh 我再次使用命令git checkout -b release_1签出release_1,这实际上是一个新的分支release_!而不是从origin签出已经存在的分支release_1。 通过移除“-b”开关解决了问题

这很傻,但可能会发生。假设你的分支名称前缀是一个问题引用(例如#91-fix-html-markup),如果你这样合并:

$ git merge #91-fix-html-markup

它不会像预期的那样工作,因为#之后的所有内容都被忽略,因为#开始一个内联注释。

在这种情况下,你可以重命名分支,省略#或使用单引号环绕分支名称:git merge '#91-fix-html-markup'。

我也有同样的问题。我在遥控器上做了修改,它仍然显示“已经更新”。重新克隆存储库为我解决了这个问题。

我有一种重新合并它的方法,我的场景是我需要合并一个发布分支。

条件:发布分支代码是金的。意思是master是不正确的而release分支是正确的。

现象:将发布版本合并到主版本时,主版本中不正确的部件没有与发布版本中的部件一起更新。

以下是步骤,免责声明:我对git的了解有限,一定有更好的方法来实现它。

checkout release branch, do a pull. [Commit #A] merge latest master to release [Commit #B] (incorrect file will write to release branch) do a reverse commit of the [Commit #B] BUT keep it in stage (if the reserve commit is committed as [Commit #C] then do a soft reset to Commit #B) (this essentially reverse the incorrect files) edit the files, check whether these are correct, discard the unwanted ones (if there is any) stash the changes in step 4 [Stash{X}] reset release back to Commit #A (same as remote) merge latest master to release again [Commit #D] (diff hash should be the same but commit hash is different than b) Apply stash {x} Commit and merge to master.

编辑:第9步可以发生在本地,只是看看预期的部分是否已应用,如果你碰巧不得不使用一个公关在远程。

如果将分支A合并到分支B报告“Already up to date”,则反过来并不总是正确的。只有当分支B是分支A的后代时才成立,否则 分支B可以有A中没有的变更。

例子:

在master上创建分支A和B 您在master中做了一些更改,并只将这些更改合并到分支B中(不更新或忘记更新分支A)。 你在分支A中做了一些改变,并将A合并到B。

在这一点上,合并A到B报告“已经更新”,但分支是不同的,因为分支B有来自主的更新,而分支A没有。