Search code examples
c#.netbashgit

git - show only the projects (csproj) whose files have changes


This question is similar to git diff - only show which directories changed.

Let's say I have the following project structure:

src
  - project.sln
  - Project1
    - Foo.cs
    - Bar.cs
    - Project1.csproj
  - Project2
    - Fizz.cs
    - Buzz.cs
    - Project2.csproj
  - Project3
    - HelloWorld.cs
    - Project3.csproj

Now, let's say that I update Foo.cs, Bar.cs and Fizz.cs. This means that src/Project1 and src/Project2 have changes in them.

In this case, I would like to be able to ask git to return the paths of src/Project1/Project1.csproj and src/Project2/Project2.csproj.

I suppose it would also be good to only get the root dir of each project (src/Project1/ and src/Project2).

How can I accomplish this with git and bash?


For those that feel like this is an xyproblem, you are correct. The problem I am having is that dotnet format (which formats your .NET code) needs to analyze the entire solution, just to format 2 files (for example).

By knowing the exact projects that change, I could instruct dotnet format to only format those project instead, hopefully improving performance.


Solution

  • Check dotnet-affected. Probably that's what you need.