在git中始终忽略某个合并提交 [英] Always ignore a certain commit on merge in git

查看:243
本文介绍了在git中始终忽略某个合并提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用git处理我的第一个项目,并遇到了问题。

I am working on my first project using git and have ran into an issue.

回购包含一个客户端/服务器应用程序。我有一个'主'和'测试'分支,意图是主人总是与部署的一样。

The repo contains a a client/server app. I have a 'master' and 'test' branches, with the intent that master is always the same as what's deployed.

我的问题有3-4个地方存储服务器URL的代码库。我想在测试分支中更改此项,但不是在主分支中。当然,问题是,无论何时我想合并回master,git都希望将此更改置于master中。

My problem there are 3-4 places in the codebase where the server URL is stored. I want to change this in the 'test' branch, but not in the 'master' branch. The problem is, of course, that whenever I want to merge back to 'master', git wants to put this change in 'master'.

我可以选择合并和合并所有的提交,但有问题的提交,但这似乎是单调乏味的每一个合并。什么是最好的方式来做到这一点?

I can do a selective merge and merge all the commits but the one in question, but this seems tedious to do for every single merge. What's the best way to do this?

我从来没有在任何 SCM中遇到过这个问题,所以也许我只是想解决这个问题所有错误。

I've never had this problem in any SCM, so maybe I"m just going about this all wrong.

推荐答案

您希望在该更改中合并为未实际合并,但将其标记为历史记录。你会知道从哪里得到后续变化。

You want to merge in that change as not being actually merged, but mark it so in history. This way you will know from where to get subsequent changes.

有两种方法可以做到这一点:一种是

There are a couple of ways to do this. One is

git checkout master
git merge -s ours --no-ff testing
git checkout testing
git merge -s ours --no-ff master

git checkout master
git merge testing --no-commit --no-ff
git checkout HEAD -- .
git submodule update # this is optional and only needed if you have submodules
git add -A
git commit
git checkout testing
git merge master --no-commit --no-ff
git checkout HEAD -- .
git submodule update # this is optional and only needed if you have submodules
git add -A
git commmit

现在你有2个分支使用不同的配置,但那些提交在重要的 merge-base 之前。

Now you have 2 branches with differing configs but those commits are before the important merge-base.

现在你需要编写这样的脚本进行特殊合并,这是真正的底层底层 - 这是忽略之前发生的事情的唯一方法:

Now you need to script something like this to do the special merge, which is really a rebase underneath -- that's the only way to ignore what happened before:

git checkout master
git merge --no-ff -s ours testing
git checkout -b temp testing
git rebase -s recursive -Xtheirs master # these are the conflicts we care about
git reset --soft HEAD@{2}
git add -A
git submodule update
git commit --amend -C HEAD@{2}
git push . +HEAD:master
git checkout master
git branch -d temp

只是重新分配你在分支测试中没有掌握的东西,并使它看起来像一个合并。因为它将其作为合并进行存储,所以随后可以针对要发布为主的其他分支运行此操作。所以你可以用&& s来分隔所有这些命令,用一个参数代替测试,用第二个参数变量master和master代替它:

This just rebases what you don't have on master in branch testing and makes it look like a merge. Because it stores it as a merge, you can subsequently run this against other branches you want to publish to master. So you could separate all those commands with &&s, replace testing with an argument, master with the second argument variables and alias it:

git config alias.smart-merge '...'

,以便您可以发布如下所示的更改:

so that you can publish changes like so:

git smart-merge testing master
git smart-merge feature2 master

无论在什么时候,这些应该会给你测试和功能2 2可能已经被合并到历史中了。

which should give you both testing and feature2 no matter at which point those 2 may have been merged in history already.

另外考虑启用rerere,因为脚本没有冲突。所以如果你想发布,你可以先做一个定期的rebase,记录冲突解决方案。现在,您可以改变脚本以利用这些脚本,而不会中断冲突。

Also consider enabling rerere as the script expects no conflicts. So if you do want to publish, you can do a regular rebase first, recording conflict resolutions. Now you can alter the script to take advantage of those and not break on conflicts.

重新分配冲突解决方案可能会很痛苦。但不是在这种情况下,因为我们只使用master来发布。其他分支操作仍然通过常规合并或rebase完成。

Rebase conflict resolution can be a pain. But not in this case as we only use master to publish. Other branch manipulation is still done via regular merge or rebase.

- 或 -

非平凡是污迹干净的脚本。看看progit.org/book中的git attributes章节。

The non trivial is smudge clean scripts. Take a look at the git attributes chapter in progit.org/book.

希望这有助于您。

这篇关于在git中始终忽略某个合并提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆