Git:忽略编译后的Google Go文件。

huangapple go评论81阅读模式
英文:

Git: Ignore compiled Google Go

问题

我的编译后的Go代码在Linux上没有扩展名。有没有处理在.gitignore文件中忽略这些文件的提示?

英文:

My compiled Go code does not end with an extension on Linux.

Any tips for handling ignoring these in the .gitignore file?

答案1

得分: 15

如果您正在使用go工具构建代码,您可以使用-o标志来指定输出文件名,因此您可以例如使用go build -o bin/elf,然后将bin/*添加到您的.gitignore文件中。

英文:

If you are using the go tool to build your code you can use the -o flag to specify the output file name, so you can for example use go build -o bin/elf and then add bin/* to your .gitignore file.

答案2

得分: 9

将您的构建产品与源代码分开。这有几个优点:

  • 您可以同时启动多个相同代码的构建,而无需创建多个克隆
  • 您可以确信您已经进行了干净的构建;rm -rf objdir将删除一个有错误的make clean会忽略的文件
  • 您可以从只读的源代码副本(例如CD-ROM)启动构建
  • 您不太可能意外提交生成的文件
  • git clean -dxf将清理您的源代码树,但不会触及您构建的文件

请注意,GNU Automake和Make支持一个名为VPATH的功能,可以轻松地将源代码树与构建树分开。

英文:

Keep your build products separate from your source code. This has several advantages:

  • you can start many different builds of the same code at the same time without creating multiple clones
  • it's easy to be confident that you've really done a clean; rm -rf objdir will remove files that a buggy make clean will miss
  • you can kick off a build from a read-only copy of the source tree (e.g., CD-ROM)
  • you're less likely to accidentally commit generated files
  • git clean -dxf will clean your source tree, but won't touch your built files

Note that GNU Automake and Make support a feature called VPATH to make it easy to separate the source tree from the build tree.

答案3

得分: 3

只需在您的.gitignore文件中添加文件的名称?虽然繁琐,但这样做是有效的。

英文:

Just add the names of the files in your .gitignore? Tedious, but it will work.

答案4

得分: 3

.gitignore语言不是图灵完备的。它只能匹配相对简单的模式。这意味着你需要另外一个能够确定应该排除哪些可执行文件的工具。因此,编写一个脚本,根据可创建的可执行文件的名称来创建.gitignore文件。如果你想要更高级一点,可以创建一个别名,在git add之前运行该脚本。

英文:

The .gitignore language isn't Turing complete. It can only match fairly simple patterns. This just means you need something else that can figure out what possible executables should be excluded. So, write a script that creates .gitignore based on the names of the executables that can be created. If you want to be fancy, make an alias that runs it before git add.

答案5

得分: 0

只忽略所需目录中的所有文件,除了go文件。

例如,假设您的main.go和名为main的二进制文件位于同一个目录中,即main/main.gomain/main

修改您的.gitignore文件以忽略主目录中的所有文件,除了具有.go扩展名的文件。

main/*
!main/*.go
英文:

Just Ignore all files in the required directory except go files.

E.g assume your main.go and binary file with name main are in the same directory i.e main/main.go and main/main

Modify your .gitignore to ignore all files inside the main directory except files with the .go extension

main/*
!main/*.go

huangapple
  • 本文由 发表于 2012年3月31日 08:52:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/9952061.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定