git merge 不是时已经是最新的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22316165/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git merge Already up to date when it is not
提问by Warwick Hall
While working on a project using git and bitbucket.com, there are the following branches:
在使用 git 和 bitbucket.com 处理项目时,有以下分支:
master
development
uat
production
When I started the project work I took a git clone of development (thinking naturally that it contained the state of the art code). Months of work later, and now it turns out that the code in production branch (which is currently running in production) has a later version than the code I started with in development branch.
当我开始项目工作时,我使用了一个 git clone 开发(很自然地认为它包含最先进的代码)。几个月后的工作,现在事实证明生产分支(目前正在生产中运行)中的代码比我在开发分支中开始使用的代码版本更高。
When I attempt to:
当我尝试:
git checkout development
git merge production
it says "Already up to date". When I go:
它说“已经是最新的”。我去的时候:
git diff production..development
it spits out lots of changes that say production branch has code that is not in development branch. How can I make the production code merge with development code without wiping my months of work?
它吐出很多变化,说生产分支的代码不在开发分支中。如何在不抹掉我几个月的工作的情况下使生产代码与开发代码合并?
采纳答案by torek
You may not want to merge
, but rather to rebase
. That is, take the commits you've made, the commits youadded to branch development
—the ones that were not there when you first did your clone
, but are there now—and see what changes each one made in sequence; and apply those changes, again in sequence, on top of branch production
.
您可能不想merge
,而是想要rebase
。也就是说,获取你所做的提交,你添加到分支的提交development
——那些在你第一次做你的时候不存在的提交clone
,但现在已经存在了——并查看每个提交按顺序进行了哪些更改;并在 branch 之上再次按顺序应用这些更改production
。
(Some of them will probably not go in cleanly: changes to production
that are not present in development
will mean that some, maybe many, of the changes you made need to be modified to fit in. Worse, changing one of your changes will almost certainly affect more of your changes, so this rebase could be difficult.)
(其中一些可能不会干净利落:对production
不存在的更改development
将意味着您所做的更改中的一些,也许很多,需要进行修改以适应。更糟糕的是,更改您的一项更改几乎肯定会影响您的更多更改,因此此变基可能很困难。)
That said... "Up to date" does not mean the code is the same, by any means. It just means that the commit graphshows that there is nothing new to bring in. That, in turn, implies you (or someone else) already did the merge. The treeattached to the final merge (the result of the merge) is not what you want, but the only thing git can see is that the merge is done. See Why after merge does GIT say “Already upto date”, but differences between branches still exist?for an example involving git revert
, for instance.
也就是说......“最新”并不意味着代码是相同的,无论如何。这只是意味着提交图显示没有任何新内容可以引入。这反过来意味着您(或其他人)已经进行了合并。附加到最终合并的树(合并的结果)不是你想要的,但 git 唯一能看到的就是合并完成了。看到为什么合并后GIT说“已经是最新的”,但分支之间的差异仍然存在?例如,涉及git revert
,例如。