问题描述
我有一个带有两个分支A
和B
的存储库.
I have a repository with two branches, A
and B
.
它们本来是相同的代码,但是针对它们所依赖的库的不同版本.
They are meant to be the same code, but aimed at different versions of the libraries they depend on.
因此A/file1.js
中可能有一个摘要,如下所示:
So A/file1.js
might have a snippet in it like so:
this.actor.bar();
B/file1.js
可能有:
// `bar` had its name changed to `foo` in version X.Y of library Z
this.actor.foo();
然后我继续说A
并进行一堆更改,这些更改与库Z
的两个版本都兼容,并希望将它们合并到B
中.
Then I go along into A
say and make a whole bunch of changes that are compatible with both versions of library Z
and want to merge them into B
.
有什么办法可以告诉我,进行合并,但忽略*.bar()
变为*.foo()
的行吗?"
Is there any way I can tell mercurial, "do a merge but ignore the lines where *.bar()
becomes *.foo()
"?
基本上,由于分支A
和B
所依赖的库版本不同,有一些代码块有所不同,但是我编写了这样的代码:代码是相同的.
Basically there are a few blocks of code that differ between branches A
and B
because of the version of library they depend upon, but I've written the code such that asides from those lines, the rest of the code is identical.
我只是不想在每次合并时都必须处理这些代码块,因为否则我更容易混淆合并并在其中切换一些代码块.
I just don't want to have to deal with these blocks of code every time I merge, because otherwise I'm more prone to fudge up the merge and switch some of these blocks around.
我唯一能想到的就是以某种方式为每个调用自定义每个文件的diff --ignore-matching-lines [impressively_long_argument]
的文件制作不同的差异预设-这似乎是错误的方法!
The only thing I can conceive is somehow making a different diff preset for each file that calls diff --ignore-matching-lines [impressively_long_argument]
that is custom to each file - this seems like the wrong way to do it!
(我可以在git中执行此操作吗?这是我要切换版本控制系统的一项功能,尽管我不知道如何实现它.或者解决方案在于找到一种复杂的diff
工具).
(Can I do this in git? This is a feature I'd switch versioning systems for, although I have no idea how one would implement it. Or perhaps the solution lies in finding a sophisticated diff
tool).
推荐答案
Git和Mercurial都比您想象的要容易得多(比svn或CVS更容易).那是因为git和Mercurial合并更改而不是差异.
Git and Mercurial both handle this more easily that you're imagining (and easier than, say, svn or CVS do). That's because git and Mercurial merge changes not differences.
如果您有两个分支A和B,并且在执行此操作时已将分支A中的bar
更改为foo
:
If you have two branches, A and B, and you've changed bar
to foo
in branch A when you do this:
hg update B
hg merge A
它将合并到A中当前尚未合并到B中的所有变更集中.这将包括从bar
到foo
的更改,并且您必须手动排除该特定更改,但只有一次.
it will merge in all the changesets currently in A that haven't yet been merged into B. That will include your bar
to foo
change and you'll have to manually exclude that specific change but only that one time.
下次执行时:
hg update B
hg merge A
它将再次合并到A中当前尚未合并到A的所有变更集中,但是由于将bar
到foo
的变更集已经合并到中,因此所有,因为A拥有foo
s,B拥有bars
s,因为在合并的变更集中未创建差异,因此变更不会被应用到B而且您不必再次手动拒绝它.
it will again merge in all the changesets currently in A that haven't been merged to A, but since the changeset that does bar
to foo
has already been merged in it doesn't matter at all that A has foo
s and and B has bars
s because that difference wasn't created in the changesets now being merged, that change won't be applied to B and you don't have to manually reject it again.
这是具有完整图形历史记录的CVS所带来的关键优势之一.您没有合并两个快照,而是将分支A的新差异应用到分支B,因此,如果差异不是新的,则不必重新拒绝它-系统会记住,哦,我记得,您不想要那个." .
This is one of the key advantages that a CVS with a full graph history brings. You're not merging two snapshots, you're applying the differences that are new in branch A to branch B, so if a difference isn't new you don't have to re-reject it -- the system remembers, "oh, I remember, you didn't want that".
这篇关于合并文件时忽略某些*行*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!