【问题标题】:How can i skip some files while taking git diff?如何在使用 git diff 时跳过一些文件?
【发布时间】:2019-03-08 11:58:08
【问题描述】:

我想从 git diff 中跳过一些文件。 我无法将它们放在 .gitignore 列表中,因为我需要它们并不断更新。

.gitattributes 似乎为我解决了这个问题。但是我不知道该怎么做。

我尝试在签入后将文件放入 .gitignore。但我注意到 git 在进行 git diff 时仍然会考虑来自 .gitignore 的那些文件。

我想要this 之类的东西,但它不适用于我的 git 版本,即(git 版本 2.14.1.windows.1)

This question 讨论通过将要跳过的文件作为参数传递给 git diff 命令来跳过 git diff 中的文件。但如果我这样做,我必须跟踪所有文件。我想将跳过列表放在某种 .git_______ 文件中,git 会在获取 git diff 时隐式使用该文件来跳过

【问题讨论】:

  • @RomainVALERI 不完全是!我想保留所有要跳过的文件的列表,同时将 git-diff 保存在一个单独的文件中,如 .gitattributes 这消除了我在使用 git diff 时跟踪我跳过哪些文件的头痛,如上面链接中提到的他在哪里将要跳过的文件列表作为参数传递
  • 你链接的“类似这样的东西”早在 2.14 之前就已经在 Git 中了。
  • @jthill 是的!可以弄清楚。谢谢

标签: git


【解决方案1】:

我们可以在 git 仓库根目录的 .gitattributes 文件中添加所有要跳过的文件

在 windows 上使用此命令 git config diff.nodiff.command C:/"Program\ Files"/Git/usr/bin/true,在 mac 上使用 git config diff.nodiff.command usr/bin/true 设置 git 配置。

.gitattributes 内容可以如下:

Readme.md diff=nodiff
xzy.txt diff=nodiff

那么这应该跳过 Readme.md 和 xyz.txt 文件更改,同时进行 git diff!

【讨论】:

  • 另外,您可以在.git/info/attributes 中拥有一个repo-local 属性文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-23
  • 1970-01-01
  • 1970-01-01
  • 2012-08-21
  • 2021-10-22
相关资源
最近更新 更多