Gav*_*vin 15 git vb6 version-control dvcs
我们公司在VB6中有一个很大的代码库,我们目前使用VSS,尽管我们讨厌它,但它至少集成到了VB6 IDE中.
我自己的团队,正在使用.NET,现在正在寻找替代的SCM,比如我个人最喜欢的Git.使用Git Extensions,我们似乎能够很好地将Git命令集成到Visual Studio IDE中.
但是,有人问过这个问题:Git也可以用于我们的VB6代码库吗?
当然我假设文件本身在git存储库中可以正常工作,但毫无疑问,开发人员会抱怨他们是否必须使用命令行来完成所有源代码控制.但有没有人有使用VB6和Git的经验?VB6 IDE中可以进行任何集成吗?或者,没有IDE集成可能没那么麻烦?
我是否会获得第一个创建[ vb6 ]和[ git ] 的荒谬标签组合的徽章?
Kei*_*ped 15
我发现这个解决方案适用于我们的情况.它为以前的答案增加了一点,并解决了我们的项目与git一起使用的所有许多问题.
.gitattributes
# Set the default behavior, in case people don't have core.autocrlf set.
* text eol=auto
*.bas text eol=crlf
*.frm text eol=crlf
*.log text eol=crlf
*.vbp text eol=crlf
*.cls text eol=crlf
*.vbw text eol=crlf
*.dsr text eol=crlf
*.ini text eol=crlf
*.res binary
*.RES binary
*.frx binary
*.exe binary
*.dll binary
*.ico binary
*.gif binary
*.ocx binary
*.tlb binary
*.ocx.bin binary
*.ism binary
*.bin binary
*.aps binary
*.ncb binary
*.exe.compat binary
*.ocx.compat binary
Run Code Online (Sandbox Code Playgroud)
的.gitignore
.DS_Store
.Trashes
*.vbw
*.csi
*.exp
*.lib
*.lvw
*.dca
*.scc
*.tmp
<name of built binary, exe, dll or ocx>
Run Code Online (Sandbox Code Playgroud)
小智 6
已经使用Git来管理VB6项目大约一年了.从未遇到任何IDE集成.我个人喜欢命令行,所以我看起来并不多.我遇到的两个主要问题是:
这确实是对 KeithTheBiped 等人的其他优秀评论的补充......
但是,可以在一定程度上强制 VB6 中的即时窗口像现代终端窗口一样工作,但有一些注意事项。如果我们创建一个帮助函数来运行命令,以某种方式捕获输出,然后使用 Debug.Print 将其中继回即时窗口 SIMILAR 到终端窗口,但当然没有任何交互元素。
这适用于大多数命令,但无法捕获git push
阶段中的某些输出。一个可以接受的折衷方案,为了方便没有 shell (imo)。
我们可以通过命令提示符 ( cmd.exe /c
) 使用针对临时文件的1>
和2>
管道来做到这一点。我不提供几个底层函数,但如果您还没有它们,请提供源。
考虑以下函数:
Public Function RunCmdToOutput(ByVal cmd As String, Optional ByRef ErrStr As String = "") As String
Const p_enSW_HIDE = 0
On Error GoTo RunError
Dim A As String, B As String
A = TempFile
B = TempFile
ShellAndWait "cmd /c " & cmd & " 1> " & A & " 2> " & B, p_enSW_HIDE
RunCmdToOutput = ReadEntireFileAndDelete(A)
ErrStr = ReadEntireFileAndDelete(B)
Exit Function
RunError:
RunCmdToOutput = ""
ErrStr = "ShellOut.RunCmdToOutput: Command Execution Error - [" & Err.Number & "] " & Err.Description
End Function
Run Code Online (Sandbox Code Playgroud)
你会需要:
完成此操作后,可以成功运行任何简单的执行并输出到立即窗口,如下所示:
?runcmdtooutput("ver")
Microsoft Windows [Version 10.0.16299.309]
Run Code Online (Sandbox Code Playgroud)
从这里,您可以运行 Git,并将大多数内容显示到立即窗口中,并且可以像那样简单地使用它,但我们可以做得更好。
假设您已经安装了命令行 Git 并且更新了路径以使其可用,您可以创建一些新函数(希望在模块中):
Private Function GitCmd(ByVal C As String, Optional ByVal NoOutput As Boolean = False) As String
Dim ErrSt As String
GitCmd = RunCmdToOutput(C, ErrSt)
If Not NoOutput Then Debug.Print GitCmd ' Because it also returns the string
If ErrSt <> "" Then Debug.Print "ERR: " & ErrSt
End Function
Public Function Git(ByVal C As String) As Boolean
GitCmd "git " & C
Git = True
End Function
Run Code Online (Sandbox Code Playgroud)
从这里,您几乎可以从直接窗口运行 Git 命令。请记住,Git() 是一个函数,因此您必须将参数作为字符串传递... 只是一个必需的字符。当然,VB 会自动完成一个字符串,所以你不需要完全的尾随,但我会包括它。使用语法:
Git "status"
Git "add ."
Git "commit -m ""Some Git Commit"""
Git "pull -r"
Git "push"
Run Code Online (Sandbox Code Playgroud)
它不允许交互式 git 命令 ( git add -p
),但是,您可以暴力破解它 ( git add . -f
)。但是,这些命令会运行并直接将其输出显示到“立即”窗口中,而无需做太多其他工作。
git "status"
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
...
Run Code Online (Sandbox Code Playgroud)
你明白了。
从那里,您还可以自动化操作。创建辅助函数来批处理常用的 Git 命令等,或者只是消除一些笨拙的语法。使用RunCmdToOutput
,您还可以重新设计其中的一些内容以使用 MsgBox(如果愿意),但我认为立即窗口足够直观。
在某些时候将任何功能限制为仅在 IDE 中运行也可能很重要,但这是可选的。
Public Function IsIDE() As Boolean
On Error GoTo IDEInUse
Debug.Print 1 \ 0 'division by zero error - Debug is ignored by compile
IsIDE = False
Exit Function
IDEInUse:
IsIDE = True
End Function
Public Function GitStatus()
If Not IsIDE Then Exit Function
GitCmd "git status"
GitStatus = True
End Function
Run Code Online (Sandbox Code Playgroud)
您必须创建.gitattributes文件才能使用Windows行尾(crlf),因为git诞生于unix。
# Declare files that will always have CRLF line endings on checkout.
*.vbp text eol=crlf
*.frm text eol=crlf
*.cls text eol=crlf
*.bas text eol=crlf
*.dsr text eol=crlf
*.ini text eol=crlf
# Denote all files that are truly binary and should not be modified.
*.frx binary
*.exe binary
*.dll binary
*.ocx binary
Run Code Online (Sandbox Code Playgroud)
还使用以下几行创建.gitignore文件:
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.vbw
*.tmp
*.scc
*.dca
Run Code Online (Sandbox Code Playgroud)
VB6 作为代码库(即文本文件)有何不同,导致它不适合 git?
文化完全是另一回事:如果您有很多无能的开发人员无法处理命令行,那么解决方法可能包括尽可能远离 VB6。
唯一的潜在问题是 Windows 在 git 世界中有点像二等公民。如果您发现 git 在您的环境中运行得不太好,您可能想尝试 bazaar 或 Mercurial。