In my case, I have a csproj file which looks like
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LocalLibrary\LocalLibrary.csproj" />
</ItemGroup>
</Project>
When other developers clone and work on the project, they may place LocalLibrary
in different locations...
So I want the remote to only contain
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
</Project>
And then when they add their own reference to the project, and their csproj file is updated accordingly, git will ignore that addition.
I imagine this is the only change that will ever be made to the csproj file, and if not (e.g. adding a new package dependency) they can add -f
and "hack around" in their rare cases to update the remote.
So I thought at first I would try:
- Commit the desired partial of that file, as shown in the second formatted block above
- Update the gitignore to ignore this file
- Commit the new gitignore
- Hey presto! All future changes to the csproj ignored
But actually after step 3, git status
still shows Modified: x.csproj
.
I looked it up, looks like this can be resolved by committing a git rm --cached x.csproj
, but that will also delete the file from the remote... which I don't want.
I want to have the template of the file in the remote, but ignore developers' local individual changes to it.
How can I resolve this?