How to ignore directory on git diff --no-index?

不羁的心 提交于 2020-03-22 03:35:12

问题


I am trying to create a colorized diff between two folders in the same repository (This may be the totally wrong approach).

I believe one way of achieving this is through git diff --no-index folder1 folder2 and it will automatically create a patch for you (Cool).

However, the diff also includes (as one might expect), all of the .gitignore'd files as well.

folder1
  node_modules
  src/
  .gitignore
  package.json
  README.md

folder2
  node_modules
  src/
  .gitignore
  package.json
  README.md

I would like to ignore node_modules.

Possibilities? Alternatives?


回答1:


You can try and use the assume-unchanged flag
https://git-scm.com/docs/git-update-index

--[no-]assume-unchanged

When this flag is specified, the object names recorded for the paths are not updated.
Instead, this option sets/unsets the "assume unchanged" bit for the paths.

When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.



来源:https://stackoverflow.com/questions/34776768/how-to-ignore-directory-on-git-diff-no-index

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!