1

Is there a way I can prevent git from auto-merging AssemblyInfo.cs (or disbling its behavior of detecting "oh, it's the same change, I can skip it")? If I increased the version the same way in two branches, and then merging both, I would like to handle this as conflict.

I start off in branch master with

[assembly: AssemblyVersion("1.1.*")]

Then I create two branches A and B, making changes to the project. In both branches, I change the AssemblyVersion

[assembly: AssemblyVersion("1.2.*")]

Now I merge branch A, then branch B. When merging branch B, git doesn't even consider this as conflict, since both commits make the same change.

Example:

git init Bar
cd Bar
echo '[assembly: AssemblyVersion("1.1.*")]' > AssemblyVersion.cs
git add AssemblyVersion.cs
git commit -m "Initial commit"

git checkout -b branchA master
echo -e "class A\n{\n}" > ClassA.cs
git add ClassA.cs
echo '[assembly: AssemblyVersion("1.2.*")]' > AssemblyVersion.cs
git commit -a -m "Add class A"

git checkout -b branchB master
echo -e "class B\n{\n}" > ClassB.cs
git add ClassB.cs
echo '[assembly: AssemblyVersion("1.2.*")]' > AssemblyVersion.cs
git commit -a -m "Add class B"

git checkout master
git merge --no-ff branchA -m "Merge Branch A"
git checkout master
git merge --no-ff branchB -m "Merge Branch B"

A custom merge filter won't work, since this is only executed on a three-way-merge.

Is there a solution to this?

Andreas Duering
  • 1,560
  • 2
  • 12
  • 21
  • If you want to ignore(disabling git behavior of detecting the file), you can add the file to `.gitignore`. – ParthS007 Apr 11 '18 at 14:32
  • @ParthS007 ah, maybe I explained that wrong. I still want to version control the file, I just don't want git to auto-merge. – Andreas Duering Apr 11 '18 at 14:34
  • [This answer](https://stackoverflow.com/a/41825703/1614641) suggests (near the bottom) a custom merge strategy in addition to the custom driver - but it sounds like you'll have to do a lot of plumbing. – mcmlxxxvi Feb 25 '21 at 08:29

0 Answers0