git - 如何从 git diff --no-index 中排除文件和目录

标签 git diff git-diff

如何从 git diff --no-index 中排除文件和目录?

例如,我想显示两个目录之间的差异 project1 & project2而忽略他们的顶级.git目录( project1/.gitproject2/.git )及其所有 .DS_Store文件。

最佳答案

这不是您所要求的,但它可能会给您想要的结果:添加 project2作为 project1 的 Remote 而只是 git diff他们的 HEAD s。

git remote add other ../project2/.git
git fetch other

# Perform the diff
git diff other/HEAD
如果您的 project2还不是一个 Git 存储库,你可以暂时让它成为一个(他的 Josiah Yoder 的帽子提示 comments ):
# Set up project2 repo
cd ../project2
git init
git add .

# Add as remote from project1
cd ../project1
git remote add other ../project2/.git
git fetch other

# Perform the diff
git diff other/master

# Clean up
git remote remove other
cd ../project2
rm -r .git

关于git - 如何从 git diff --no-index 中排除文件和目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49969016/

相关文章:

git:如何添加自定义 merge 策略?

windows - 在 Windows 下使用 ssh 克隆 github.com 的 repo 时出现 "no address associated with name"错误

GitHub for Windows 表示即使差异为空,也有未提交的更改

git - 致命: This operation must be run in a work tree on pre-receive hook

git - 在 Visual Studio Code 中更改 Git 用户

xml - 差异算法

linux - 如何让 Subversion 使用第三方差异工具?

java - 如何忽略两个文件中的注释变化和空行变化?

git - Cygwin 上的 Intellij 差异和 merge 工具

git - git SourceTree中停止跟踪和丢弃文件有什么区别