我有一个git仓库,有2个分支:master和test。
主分支和测试分支之间存在差异。
两个分支都提交了所有更改。
如果我这样做:
git checkout master
git diff test
屏幕上会出现一个充满变化的屏幕,显示不同之处。我想合并测试分支中的更改,这样做:
git merge test
但是得到的信息是"Already - updated "
但是,检查每个不同分支下的文件可以清楚地显示出差异。
这里的问题是什么,我如何解决它?
我有一个git仓库,有2个分支:master和test。
主分支和测试分支之间存在差异。
两个分支都提交了所有更改。
如果我这样做:
git checkout master
git diff test
屏幕上会出现一个充满变化的屏幕,显示不同之处。我想合并测试分支中的更改,这样做:
git merge test
但是得到的信息是"Already - updated "
但是,检查每个不同分支下的文件可以清楚地显示出差异。
这里的问题是什么,我如何解决它?
当前回答
确保先签出想要合并的分支,然后拉出它(这样您的本地版本与远程版本匹配)。
然后签出到你想要合并的分支,你的git合并应该可以工作。
其他回答
发生这种情况是因为您要合并的分支的本地副本已经过期。我有我的分支,叫MyBranch我想把它合并到ProjectMaster中。
_>git status
On branch MyBranch-Issue2
Your branch is up-to-date with 'origin/MyBranch-Issue2'.
nothing to commit, working tree clean
_>git merge ProjectMaster
Already up-to-date.
但我知道有些变化需要合并!
事情是这样的,当我输入git合并ProjectMaster时,git会查看这个分支的本地副本,这可能不是当前的。要查看情况是否如此,我首先告诉Git检查并查看我的分支是否过期,如果是的话,使用fetch获取任何更改。然后我跳到我想合并的分支,看看那里发生了什么……
_>git fetch origin
_>git checkout ProjectMaster
Switched to branch ProjectMaster
**Your branch is behind 'origin/ProjectMaster' by 85 commits, and can be fast-forwarded.**
(use "git pull" to update your local branch)
啊哈!我的本地副本在85次提交时就过时了,这说明了一切!现在,我拉下我所遗漏的更改,然后跳转到MyBranch并再次尝试合并。
_>git pull
Updating 669f825..5b49912
Fast-forward
_>git checkout MyBranch-Issue2
Switched to branch MyBranch-Issue2
Your branch is up-to-date with 'origin/MyBranch-Issue2'.
_>git merge ProjectMaster
Auto-merging Runbooks/File1.ps1
CONFLICT (content): Merge conflict in Runbooks/Runbooks/File1.ps1
Automatic merge failed; fix conflicts and then commit the result.
现在我有另一个问题要解决…
我有一种重新合并它的方法,我的场景是我需要合并一个发布分支。
条件:发布分支代码是金的。意思是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步可以发生在本地,只是看看预期的部分是否已应用,如果你碰巧不得不使用一个公关在远程。
Git merge origin/master而不是Git merge master为我工作。所以要合并master到feature分支,你可以使用:
git checkout feature_branch
git merge origin/master
合并总是在当前HEAD和一个或多个提交之间(通常是分支头或标签), 索引文件必须匹配HEAD提交的树(即上次提交的内容)。 换句话说,git diff——cached HEAD必须报告没有变化。 合并后的提交已经包含在HEAD中。这是最简单的情况,称为“Already - updated”。
这应该意味着测试中的提交已经合并到master中,但由于其他提交是在master上完成的,git diff test仍然会给出一些差异。
当我知道远程主机上有更改时,这种情况经常发生在我身上,所以我尝试使用git merge master合并它们。但是,这不会与远程主服务器合并,而是与本地主服务器合并。
在合并之前,签出master,然后git拉到这里。然后您将能够将新的更改合并到您的分支中。