目前我们正在为一个用 C# 编写的库建立一个本地公司的 Git 服务器。 我们的库充满了必须包含的外部 *.dll。它们将不时更新新版本。
是否可以设置 Git .config 文件,以便开发人员在合并时看到 *.dll 版本的差异而不是二进制内容?
可以使用 git hooks 来做到这一点: Git 钩子
根据您的需要,您可以使用预提交或准备提交消息,它们是用 bash 编写的,可以在 /.git/hooks 的每个存储库中找到。 可以轻松读取*.dll版本的Powershell可以这样使用:
#!/bin/sh
dllVersion=$(powershell.exe '[System.Diagnostics.FileVersionInfo]::GetVersionInfo("YourDll.dll").FileVersion')
我已经设置了 exiftool 来比较 *.exe 文件的元数据。您也可以对 *.dll 文件执行此操作。
虽然不太漂亮,但很有效。
这是 Windows Git Bash 中的一个小演示:
myuser@mypc MINGW64 ~
$ cd c:
myuser@mypc MINGW64 /c
$ mkdir difftest
myuser@mypc MINGW64 /c
$ cd difftest/
myuser@mypc MINGW64 /c/difftest
$ git init
Initialized empty Git repository in C:/difftest/.git/
myuser@mypc MINGW64 /c/difftest (master)
$ echo "*.exe diff=pefile" >>.gitattributes
myuser@mypc MINGW64 /c/difftest (master)
$ git config diff.pefile.textconv exiftool
myuser@mypc MINGW64 /c/difftest (master)
$ cp /c/Windows/System32/calc.exe somemystery.exe
myuser@mypc MINGW64 /c/difftest (master)
$ git add .
myuser@mypc MINGW64 /c/difftest (master)
$ git commit -m initial
[master (root-commit) f43eb0c] initial
2 files changed, 1 insertion(+)
create mode 100644 .gitattributes
create mode 100644 somemystery.exe
myuser@mypc MINGW64 /c/difftest (master)
$ cp /c/Windows/System32/notepad.exe somemystery.exe
myuser@mypc MINGW64 /c/difftest (master)
$ git diff
diff --git a/somemystery.exe b/somemystery.exe
index 2c6fdf1..6137c37 100644
--- a/somemystery.exe
+++ b/somemystery.exe
@@ -1,29 +1,29 @@
ExifTool Version Number : 12.65
File Name : somemystery.exe
-Directory : C:/Users/myuser/AppData/Local/Temp/git-blob-a19080
-File Size : 28 kB
-File Modification Date/Time : 2023:08:18 12:55:51+02:00
+Directory : .^M
+File Size : 201 kB^M
+File Modification Date/Time : 2023:08:18 12:55:47+02:00^M
File Access Date/Time : 2023:08:18 12:55:51+02:00
-File Creation Date/Time : 2023:08:18 12:55:51+02:00
+File Creation Date/Time : 2023:08:18 12:55:27+02:00^M
File Permissions : -rw-rw-rw-
File Type : Win64 EXE
File Type Extension : exe
MIME Type : application/octet-stream
Machine Type : AMD AMD64
-Time Stamp : 1971:09:24 18:02:24+02:00
+Time Stamp : 2070:12:03 12:32:29+01:00^M
Image File Characteristics : Executable, Large address aware
PE Type : PE32+
Linker Version : 14.20
-Code Size : 3072
-Initialized Data Size : 25088
+Code Size : 149504^M
+Initialized Data Size : 57344^M
Uninitialized Data Size : 0
-Entry Point : 0x1870
+Entry Point : 0x23f40^M
OS Version : 10.0
Image Version : 10.0
Subsystem Version : 10.0
Subsystem : Windows GUI
-File Version Number : 10.0.19041.1
-Product Version Number : 10.0.19041.1
+File Version Number : 10.0.19041.1865^M
+Product Version Number : 10.0.19041.1865^M
File Flags Mask : 0x003f
File Flags : (none)
File OS : Windows NT 32-bit
@@ -32,11 +32,10 @@ File Subtype : 0
Language Code : English (U.S.)
Character Set : Unicode
Company Name : Microsoft Corporation
-File Description : Windows Calculator
-File Version : 10.0.19041.1 (WinBuild.160101.0800)
-Internal Name : CALC
+File Description : Notepad^M
+File Version : 10.0.19041.1865 (WinBuild.160101.0800)^M
+Internal Name : Notepad^M
Legal Copyright : © Microsoft Corporation. All rights reserved.
-Original File Name : CALC.EXE
+Original File Name : NOTEPAD.EXE^M
Product Name : Microsoft® Windows® Operating System
-Product Version : 10.0.19041.1
-Warning : Possibly corrupt Version resource
+Product Version : 10.0.19041.1865^M
要使其也适用于 *.dll 文件,只需执行以下操作:
$ echo "*.exe diff=pefile" >>.gitattributes
我通过 Chocolatey 安装了 exiftool ,因此它位于我所有命令行终端(cmd.exe、powershell.exe、Git Bash、Cygwin)的路径上。
我认为您通常可以使用 exiftool 作为最后的手段。这绝对比什么都没有好。