15

is it possible to exclude a directory from displaying a diff of merge request in GitLab?

We started to version the bower_components folder (1 - to speed up app build, 2 - because bower has no .lock mechanism), but it makes trouble when doing code review - many changed files appear inside bower_components which makes the diff harder to read.

Thanks in advance

2 Answers 2

20

Since gitlab 8.8, gitlab support the .gitattributes.

So if your project does not have .gitattributes add it,

and to exclude files for diff, append:

*.<whatever> -diff

and to exclude directories from a diff:

<mydir> -diff
4
  • 1
    Nice. Is there a way to still see the diff on my machine, but ignore during gitlab review? Commented Jul 10, 2019 at 4:19
  • 1
    AFIAC: such attribute does not exist but that would be -gitlab-diff (given existing gitlab-language=LANG). But seems this recipe stopped working (it used to work). Got gitlab 13.3.6-ee. Locally skips diff (only shows "Binary files a/* and b/* differ") but in gitlab UI/MR does show full diff.
    – lukmdo
    Commented Sep 18, 2020 at 9:47
  • 2
    GitLab Community Edition 14.10.0 -diff works, but it needs to be merged in master ahead, after then it started to work 🎉 🎊
    – Luckylooke
    Commented Jun 7, 2022 at 10:47
  • The .gitattributes should be in the root project directory for it to work in gitlab. This is a difference to the git spec where the file can be in any directory.
    – Cyril
    Commented Jan 3, 2023 at 12:58
1

From here

This is a very simple workaround until there is another way to exclude vendor folders, packages, image files, etc. I just destroy the html nodes with javascript. Saving this code as a bookmark in the browser toolbar lets you filter every time you are in the diff page, just clicking in the bookmark.

javascript:var q=prompt(“Insert your filter”);if(q!=null){$(“.diff-file:contains(“+q+“)”).detach()}

The script lets you specify the route (f.ex. vendor/) or an extension (.jpeg) to delete all nodes that contains that string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.