0

From these two folders and their subfolders, I want to exclude all folders named .git from the comparison made by git diff. On other similar topics there are solutions in which there is only the exclude syntax but there are no two comparison folders and if I try to use this syntax, assuming folder_orig and folder_dest are both in home directory ~ and my current directory is home directory ~:

git diff --no-index folder_orig folder_dest ':!.git' > file.patch

Or this syntax:

git diff --no-index folder_orig folder_dest :^.git > file.patch

Or also this syntax:

git diff --no-index folder_orig folder_dest -- . :^.git > file.patch

It just shows me the command help with no explicit error messages.

I misunderstood the solution provided by the topic: Exclude a directory from git diff

with a syntax that I can't understand:

git diff previous_release..current_release -- . :^spec

?

Mario Palumbo
  • 693
  • 8
  • 32
  • 2
    What do you mean by ignore the .git folder? Do you have a .git directory being tracked in a separate git repository? ...how did that happen? – Brian61354270 Jul 17 '23 at 13:56
  • 1
    Could you provide an example of the output you're trying to omit from `git diff`? – Brian61354270 Jul 17 '23 at 13:57
  • the `folder_orig` and `folder_dest` folders and some of their subfolders contain the `.git` folder. I want to exclude all folders named `.git` from the comparison made by git diff. – Mario Palumbo Jul 17 '23 at 14:10
  • I hope I have made my question understandable. – Mario Palumbo Jul 17 '23 at 14:15
  • 1
    What is the syntax error? What are the literal commands that you are executing? `` is obviously not correct syntax – knittl Jul 17 '23 at 14:32
  • @MarioPalumbo Exclude pathspec requires non-exclude path, see https://stackoverflow.com/a/58382160/7976758 . But `.git` directories are never tracked so there is no point in excluding them. – phd Jul 17 '23 at 14:33
  • Instead, unfortunately, they are tracked. I checked the git diff output. – Mario Palumbo Jul 17 '23 at 14:34
  • @MarioPalumbo Can wee see this diff? – phd Jul 17 '23 at 14:35
  • 1
    This looks more like an error in your repo, because does not version the `.git` folders. If you do a `git log .git`, you should get no output for instance. Aside from this if you do a `git diff -h`, you will see that the two pathes to be compared must be the **last** parameters. – user1934428 Jul 17 '23 at 14:37
  • 2
    _it gives me syntax error._ I don't see any syntax error message in your posting. Copy and paste the full error message, or show a screenshot. – user1934428 Jul 17 '23 at 14:40
  • It just shows me the command help with no explicit error messages. – Mario Palumbo Jul 17 '23 at 14:42
  • @phd Simply with `git diff --no-index folder_orig folder_dest > file.patch` it gives me the difference even in the files inside the folders named .git. – Mario Palumbo Jul 17 '23 at 15:01
  • 2
    `.git` folder is internal data for git application and should not be touched or used for inspection. This smells like [XY problem](https://mywiki.wooledge.org/XyProblem). What are you trying to achieve. What kind of operation you trying to do on your repository? – Marek R Jul 17 '23 at 15:03
  • In fact I don't touch that directory, but with this simple syntax `git diff --no-index folder_orig folder_dest > file.patch`, the differences of all the files in the .git folders are also compared in the output file. – Mario Palumbo Jul 17 '23 at 15:05
  • You might as well use directly Unix diff utility, something like `diff --exclude .git folder_orig folder_dest` – Philippe Jul 17 '23 at 15:07
  • @MarioPalumbo It sounds like you have git repositories inside git repositories inside git repositories. That's not an intended way to use git, and is probably liable to corrupting the inner repos. The correct way to do something like that is with something like git [submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules), which let you combine many git repos into a single tree with a single top-level `.git` folder that git natively knows how to work with and track. – Brian61354270 Jul 17 '23 at 15:09
  • I understood the problem. The folders mentioned above contain many repositories, in fact the .git folder contained within the two main folders are not compared. Instead, .git folders contained within subfolders are compared. – Mario Palumbo Jul 17 '23 at 15:10
  • Note that `git diff --no-index folder_orig folder_dest` indicates you are trying to compare folders, but [docks says ti does something else](https://git-scm.com/docs/git-diff) (it tries compere "binary large object" - blob). – Marek R Jul 17 '23 at 15:10
  • @MarekR No, the output file shows me the differences correctly, it's not a binary comparison, but it also compares the files inside the .git folders when they are inside subfolders of the two main folders. – Mario Palumbo Jul 17 '23 at 15:12
  • This detracts from the main question though, this is not an XY problem, I just want to ignore the folder with a specific name inside any subfolders of the two main folders. Whether it's called .git or it's called spongebob, it's the same problem. – Mario Palumbo Jul 17 '23 at 15:16

0 Answers0