How to discard changes to GUIDs

Viewed 24

Occasionally I use tools to generate code which include GUIDs. These GUIDs are generated on the fly so they are never the same and thus resulting in changes which git recognizes. Here an example:

   IXMLRequestContextType = interface(IXMLNode)
-    ['{FA84DA66-04C7-4691-BE38-491BE9C56136}']
+    ['{CB3C3662-B526-46C9-A038-8A3284BCEF73}']

Usually I discard these changes manually but this time I got a 40k+ line file with thousands of changes and I thought this process must be automatable and someone out there must have had the same problem before. While this might be true I couldn't find a solution.

I tried working with git diff --word-diff=plain --word-diff-regex="\{[A-F0-9]{8}\-[A-F0-9]{4}\-[A-F0-9]{4}\-[A-F0-9]{4}\-[A-F0-9]{12}\}" which seemed promising at first but even with the help of this answer https://stackoverflow.com/a/56090786/6308948 I couldn't (reverse) apply the patch.

1 Answers

While writing the question I came up with a solution:

git diff -I "\{[A-F0-9]{8}\-[A-F0-9]{4}\-[A-F0-9]{4}\-[A-F0-9]{4}\-[A-F0-9]{12}\}" | git apply --cached

This stages all the differences which contain more than just the GUIDs, so this is still staged

-    ['{837CA9B4-25A0-4C73-B608-60980131BB15}']
+    ['{279B6000-C097-4D14-A479-BC12C277300E}']
+    procedure XSDValidate;

because of the extra line. This is suboptimal but way better than nothing at all. If someone can find a solution for this too I would very much appreciate it.

Related