简短的回答很简单:不。
长答案要复杂得多,但也等于“不”。本质上,您可以在some情况下,让 Git 相信如果有变化双方合并的变化总是冲突. See 这个答案 https://stackoverflow.com/a/38023172/1256452到一个相关的问题(虽然我真正说的是你可以将文件标记为二进制,或者设置特殊的合并驱动程序,但是即使要达到这一点,你也需要了解很多背景知识)。
如果您想避免某些文件,您可以做的是运行您的git merge
with --no-commit
:
$ git status
On branch master
nothing to commit, working directory clean
$ git checkout -b sidebranch
... lots of coding, git committing, etc
$ git checkout master
... more coding and committing, etc.,
or various merges of other branches,
so that master and sidebranch are
actually divergent (if they are
not, note that merge would
normally do a "fast forward" here)
$ git merge --no-commit sidebranch
此时,Git 将使用我在链接答案中描述的过程进行合并(通过进行两个差异,然后组合两个差异)。但它不会自动提交结果合并,即使成功了.
这意味着您现在可以执行以下操作:
$ git rm path/to/ickyfile
# we don't want this file, it's icky!
和/或这个:
$ git checkout --ours -- path/to/foo; git add path/to/foo
# we want the current (master) version of this file,
# ignoring all the changes made in the side branch
甚至像这样的东西(但不要这样做:结果有时被称为“邪恶合并”):
$ vim path/to/bar
<make changes that come from neither master nor sidebranch>
$ git add path/to/bar
一旦你完成了让不好的事情发生在一个好的合并中:-),你就可以运行git commit
来完成合并。
一般来说,如果您发现需要执行此操作,则您可能使用了错误的工具。特别是,当“正确”的事情是时,人们经常使用配置文件执行上述操作首先不要将这些文件放入 Git(或任何版本控制系统)中。
(相反,放置一个exampleVCS 中的配置文件。代替prog.conf
、添加并提交prog.conf.example
. Put prog.conf
在你的.gitignore
。如果需要,您的安装/初始化代码可以将示例配置复制到位,以进行新用户设置。)