【发布时间】:2013-07-29 19:33:33
【问题描述】:
有一个previous post about automatically adding .gitignore,但是您如何在git init 中指定一个选项,它表示要在git init 上添加相应的.gitignore?
(换句话说,能够指定使用哪个.gitignore)
这可以单独使用 git 命令还是使用一些 shell 脚本来实现?
【问题讨论】:
有一个previous post about automatically adding .gitignore,但是您如何在git init 中指定一个选项,它表示要在git init 上添加相应的.gitignore?
(换句话说,能够指定使用哪个.gitignore)
这可以单独使用 git 命令还是使用一些 shell 脚本来实现?
【问题讨论】:
如果您想依赖模板,如您链接的帖子中所示,使用模板目录,您应该有不同的模板目录,每个目录都有其正确的info/exclude 文件,并使用
git init -c --template=/path/to/template
请注意,这不会创建 .gitignore 文件,而是创建 .git/info/exclude 文件,该文件保留在此 repo 的本地,并且在推送时不会共享(.gitignore 不是这种情况)
如果您不想费心创建目录,而是从 GitHub .gitignore 获取预定义的目录,则此快速脚本会初始化一个 repo,从 GitHub 的预定义目录中获取 gitignore,并使用它进行第一次提交。
勾选available languages here,注意首字母一定要大写。
#!/bin/sh
git init .
curl -o .gitignore --fail --show-error --silent --location https://raw.github.com/github/gitignore/master/$1.gitignore
git add .gitignore && git commit -m "added gitignore from GitHub"
调用脚本git-init-more.sh、chmod +x,并将其放在你的路径中,然后你可以这样调用它:
$ git init-more Perl
【讨论】: