在 VB6 中使用 Git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2462480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:10:00  来源:igfitidea点击:

Using Git with VB6

gitvb6version-controldvcs

提问by Gavin

Our company has a large codebase in VB6, and we currently use VSS which, for all that we hate about it, at least integrates into the VB6 IDE.

我们公司在 VB6 中有一个很大的代码库,我们目前使用 VSS,尽管我们讨厌它,但至少它集成到了 VB6 IDE 中。

My own team, which is using .NET, are now looking into alternative SCMs like my personal favourite, Git. With Git Extensions, it seems we will be able to integrate Git commands into the Visual Studio IDE pretty well.

我自己的团队正在使用 .NET,现在正在寻找替代 SCM,比如我个人最喜欢的 Git。使用Git Extensions,我们似乎可以很好地将 Git 命令集成到 Visual Studio IDE 中。

However, the question has been asked: could Git be used for our VB6 codebase too?

然而,有人提出了一个问题:Git 也可以用于我们的 VB6 代码库吗?

Of course I assume the files themselves would work fine in git repositories, but no doubt developers would complain if they had to use the command-line to do all their source control. But has anyone had any experience using VB6 and Git? Any integration available from within the VB6 IDE? Or is it perhaps not that much of a hassle to not have the IDE integration?

当然,我假设文件本身在 git 存储库中可以正常工作,但毫无疑问,如果必须使用命令行来进行所有源代码控制,开发人员会抱怨。但是有没有人有使用 VB6 和 Git 的经验?VB6 IDE 中是否有任何可用的集成?或者,没有 IDE 集成可能不是那么麻烦?

And do I get a badge for being the first to create the absurd tag combination of [vb6] and [git]?

我是否因为第一个创建 [ vb6] 和 [ git]的荒谬标签组合而获得徽章?

回答by KeithTheBiped

I found this solution to work in our situation. It adds a bit more to the previous answers and solved all of our MANY issues getting our project to work with git.

我发现这个解决方案适用于我们的情况。它为之前的答案添加了更多内容,并解决了让我们的项目与 git 一起工作的所有许多问题。

.gitattributes

.git 属性

# 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

.gitignore

.gitignore

.DS_Store
.Trashes
*.vbw
*.csi
*.exp
*.lib
*.lvw
*.dca
*.scc
*.tmp
<name of built binary, exe, dll or ocx>

回答by Blasio

Been using Git to manage VB6 projects for about a year now. Never came across any IDE integration. Personally I like the command line, so I've not been looking much. The two major issues I've encountered are:

使用 Git 管理 VB6 项目大约一年了。从未遇到过任何 IDE 集成。就我个人而言,我喜欢命令行,所以我没怎么看。我遇到的两个主要问题是:

  1. VB6 IDE doesn't monitor the project files, if any of them is changed externally (e.g. using 'git reset', 'git checkout') then the project needs to be re-opened to reflect the changes.
  2. VB6 IDE will sometimes change the case of event parameters or variables when loading a project, so it's never safe to use 'git commit --all' unless you want a lot of garbage with your code changes.
  1. VB6 IDE 不监视项目文件,如果其中任何一个在外部发生更改(例如使用“git reset”、“git checkout”),则需要重新打开项目以反映更改。
  2. VB6 IDE 有时会在加载项目时更改事件参数或变量的大小写,因此使用“git commit --all”永远是不安全的,除非您希望更改代码时产生大量垃圾。

回答by mkrohn

You have to create the file .gitattributesto use windows line endings (crlf) because git was born in unix.

您必须创建文件.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

Also create .gitignore file with the following lines:

还要使用以下几行创建 .gitignore 文件:

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.vbw
*.tmp
*.scc
*.dca

回答by MarkJ

You know your developers best. Will they mind using the command line? Are they keen on IDE integration? These are personal preferences.

您最了解您的开发人员。他们会介意使用命令行吗?他们热衷于 IDE 集成吗?这些都是个人喜好。

Make sure the most respected developers understand the benefits of git and are behind the decision.

确保最受尊敬的开发人员了解 git 的好处并支持决策。

Do be aware that some VB6 source files are binary and shouldn't ever be merged: e.g. .frxfiles. I don't know git, so I don't know whether that's a problem.

请注意,某些 VB6 源文件是二进制文件,不应合并:例如.frx文件。我不知道 git,所以我不知道这是否有问题。

回答by User51

This really is an addition to the other excellent comments by KeithTheBiped, et al...

这确实是对 KeithTheBiped 等人的其他优秀评论的补充......

But, it is possible to somewhat coerce the Immediate Window in VB6 to act likea modern terminal window, with some caveats. If we create a helper function to run the command, capture the output somehow, and then use Debug.Print to relay that back to the Immediate window SIMILAR to the terminal window, but without any interactive elements, of course.

但是,可以在一定程度上强制 VB6 中的立即窗口现代终端窗口一样工作,但有一些警告。如果我们创建一个帮助函数来运行命令,以某种方式捕获输出,然后使用 Debug.Print 将其中继回即时窗口 SIMILAR 到终端窗口,但当然没有任何交互元素。

This works for most commands, but fails to capture some of the output in the git pushphase. An acceptable compromise, for the convenience of no shell (imo).

这适用于大多数命令,但无法捕获git push阶段中的某些输出。一个可接受的妥协,为了方便没有外壳(imo)。

We can do just that using the the command prompt (cmd.exe /c) using the 1>and 2>pipes aimed at temporary files. I don't supply a couple underlying functions, but provide sources if you don't have them already.

我们可以通过命令提示符 ( cmd.exe /c) 使用针对临时文件的1>2>管道来做到这一点。我不提供几个底层函数,但如果您还没有它们,请提供源。

Consider the following function:

考虑以下函数:

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

You will need:

你会需要:

  • TempFile - Return a unique and non-existant file-name that your program has read/write access to. It should probably use the GetShortPathName APIto shorten long path names.
  • ShellAndWait- The standard "start a process and wait for it to exit".
  • ReadEntireFileAndDelete - Just what it says... Grab the contents, delete the file, return the string.
  • TempFile - 返回您的程序具有读/写访问权限的唯一且不存在的文件名。它可能应该使用GetShortPathName API来缩短长路径名称。
  • ShellAndWait- 标准“启动进程并等待它退出”。
  • ReadEntireFileAndDelete - 正如它所说的......抓取内容,删除文件,返回字符串。

Once you have accomplished this and can successfully run any simple executing and output into the Immediate window like this:

一旦你完成了这个并且可以成功地运行任何简单的执行和输出到立即窗口,如下所示:

?runcmdtooutput("ver")
Microsoft Windows [Version 10.0.16299.309]

From here, you can run Git, and display MOST things into the Immediate window, and could use it as simple as that, but we can do better.

从这里,您可以运行 Git,并在立即窗口中显示大部分内容,并且可以像那样简单地使用它,但我们可以做得更好。

Assuming you have already installed a command-line Git and the path is updated so that it is available, you can create a few new functions (hopefully in a module):

假设您已经安装了命令行 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

From here, you can ALMOST run Git commands from the immediate window. Remember, Git() is a function, so you have to pass in the argument as a string... Just one necessary character. Of course, VB will auto-complete a string, so you don't NEED the trailing quite, but I'll include it. Use the syntax:

从这里,您几乎可以从直接窗口运行 Git 命令。请记住,Git() 是一个函数,因此您必须将参数作为字符串传递... 只是一个必需的字符。当然,VB 会自动完成一个字符串,所以你不需要完全的尾随,但我会包括它。使用语法:

Git "status"
Git "add ."
Git "commit -m ""Some Git Commit"""
Git "pull -r"
Git "push"

It doesn't allow interactive git commands (git add -p), but, you could just brute-force it (git add . -f). But, the commands run and directly display their output into the Immediate window without much other effort.

它不允许交互式 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)
...

You get the idea.

你明白了。

From there, you can also automate things. Create helper functions to batch commonly used Git commands, etc, or just eliminate some of the clunky syntax. With RunCmdToOutput, you can also re-work some of it to use the MsgBox, if preferred, but I thought the Immediate Window was intuitive enough.

从那里,您还可以使事情自动化。创建辅助函数来批处理常用的 Git 命令等,或者只是消除一些笨拙的语法。使用RunCmdToOutput,您还可以重新设计其中的一些内容以使用 MsgBox(如果愿意),但我认为立即窗口足够直观。

It might also be important at some point to restrict any functions to only run in the IDE, but that's optional.

在某些时候将任何功能限制为仅在 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

回答by Mark Dornian

We are doing this. We have added the following to .gitIgnore

我们正在这样做。我们已将以下内容添加到 .gitIgnore

  • *.csi
  • *.exp
  • *.lib
  • *.lvw
  • *.vbw
  • MyProject.dll
  • *.csi
  • *.exp
  • *.lib
  • *.lvw
  • *.vbw
  • 我的项目.dll

回答by hasen

What's so different about VB6 as a code base (i.e. text files) that makes it not suitable for git?

VB6 作为代码库(即文本文件)有什么不同,使它不适合 git?

The culture is another matter altogether: if you have plenty of incompetent developers who can't handle the command line, the cure would probably include running away from VB6 as far as you can.

文化完全是另一回事:如果您有很多不称职的开发人员无法处理命令行,则解决方法可能包括尽可能远离 VB6。

The only potential problem is that windows in the git world is somewhat of a second class citizen. You might wanna try bazaar or mercurial if you find git doesn't work very well in your environment.

唯一的潜在问题是 git 世界中的 windows 有点像二等公民。如果您发现 git 在您的环境中不能很好地工作,您可能想尝试 bazaar 或 mercurial。