我有一个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 Bash面对这个场景。
我们的存储库有多个分支,每个分支都有不同的提交周期,合并偶尔会发生一次。 Old_Branch被用作New_Branch的父类
Old_Branch更新了一些更改,需要与New_Branch合并
正在使用下面的拉命令,没有任何分支,从所有分支获得所有来源。
Git拉源
奇怪的是,这并没有从所有分支中拉出所有的提交。曾经认为它正如所示显示几乎所有的分支和标签。
所以要解决这个问题,已经检查出Old_Branch拉了最新的使用
git checkout Old_Branch git拉原点Old_Branch
现在查看New_Branch
git checkout New_Branch
拉了一下,确认一下
git拉原点New_Branch git合并Old_Branch
viola得到了从Old_Branch到New_Branch的冲突来修复:),这是预期的
其他回答
我有一种重新合并它的方法,我的场景是我需要合并一个发布分支。
条件:发布分支代码是金的。意思是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在尝试之前会隐藏或提交更改)
// stash changes to ensure you don't lose any edits
git checkout your-branch-that-won't-simply-merge
git stash
git checkout branch-with-changes -- .
——。参数将检出其他分支的所有文件,同时仍检出到同一分支。然后您可以按照自己的意愿添加和提交。
我还将它与 Git add -p 这将使你能够在“大块头”中进行任何变化。它会询问y/n您是否想要执行任何更改过的行块,这意味着您可以在下次提交时保留不想要的更改。
这是我找到的原始答案的链接,去点赞吧。: https://stackoverflow.com/a/15536640/8272035
89年问题 通过提供当前路径,.:
Git签出other-branch-name——。
此操作类似于在不签出文件的情况下将HEAD切换到另一个分支,但只是从“另一个方向”切换。
正如@김민준提到的,这将覆盖任何未提交的更改。如果需要的话,记得先把它们藏起来或提交到某个地方。
这很傻,但可能会发生。假设你的分支名称前缀是一个问题引用(例如#91-fix-html-markup),如果你这样合并:
$ git merge #91-fix-html-markup
它不会像预期的那样工作,因为#之后的所有内容都被忽略,因为#开始一个内联注释。
在这种情况下,你可以重命名分支,省略#或使用单引号环绕分支名称:git merge '#91-fix-html-markup'。
当我知道远程主机上有更改时,这种情况经常发生在我身上,所以我尝试使用git merge master合并它们。但是,这不会与远程主服务器合并,而是与本地主服务器合并。
在合并之前,签出master,然后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.
现在我有另一个问题要解决…