git 如何让git在合并时忽略目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14369378/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:01:58  来源:igfitidea点击:

How to make git ignore a directory while merging

gitmerge

提问by Sebastian Thiebes

As interesting and useful as the answer to How to setup a git driver to ignore a folder on mergewas, it did not answer the original question which still has me stumped.

How to setup a git driver to ignore a folder on merge的答案一样有趣和有用,它没有回答仍然让我难倒的原始问题。

Unlike the question linked to above, I have two branches with the same set of directories and for merging one into the other I need git to ignore one directory completely.

与上面链接的问题不同,我有两个具有相同目录集的分支,为了将一个分支合并到另一个分支中,我需要 git 完全忽略一个目录。

I tried it with my own merge driver as described in How do I tell git to always select my local version for conflicted merges on a specific file?but the problem with this approach is that this driver is only invoked when there is an actual conflicting file in these two branches. Whenever the changes of a file are only on one branch, git merges them without calling my merge driver.

我使用我自己的合并驱动程序尝试了它,如如何告诉 git 始终选择我的本地版本以在特定文件上进行冲突合并?但这种方法的问题在于,只有在这两个分支中存在实际冲突文件时才会调用此驱动程序。每当文件的更改仅在一个分支上时,git 会在不调用我的合并驱动程序的情况下合并它们。

This leads to changes in files in the directory that I do not want. Any idea how I could make git ignore each and every file in that directory all the time - whether it was touched or not?

这会导致我不想要的目录中的文件发生变化。知道如何让 git 一直忽略该目录中的每个文件 - 无论它是否被触及?

回答by user606723

I don't actually use Git, but I think this would work for your case:

我实际上并不使用 Git,但我认为这适用于您的情况:

Use something like what's specified here: https://gist.github.com/564416

使用类似于此处指定的内容:https: //gist.github.com/564416

git checkout master    
git merge --no-commit --no-ff development
git reset -- /path/to/folder # revert updates from path
git commit

Again, I don't use git, I am just deferring to how I think things work based on my experience with TryGit.

再说一次,我不使用 git,我只是根据我使用 TryGit 的经验来考虑我认为事情是如何工作的。

  1. checkout master
  2. merge, but don't commit, no fast forward.
  3. merges are now staged, so reset that entire directory tree
  4. commit
  1. 收银员
  2. 合并,但不要提交,没有快进。
  3. 合并现在已暂存,因此请重置整个目录树
  4. 犯罪