【问题标题】:Git init with option for auto-creation of a default .gitignoreGit init 带有自动创建默认 .gitignore 的选项
【发布时间】:2013-07-29 19:33:33
【问题描述】:

有一个previous post about automatically adding .gitignore,但是您如何在git init 中指定一个选项,它表示要在git init 上添加相应的.gitignore

(换句话说,能够指定使用哪个.gitignore

这可以单独使用 git 命令还是使用一些 shell 脚本来实现?

【问题讨论】:

    标签: git shell gitignore


    【解决方案1】:

    解决方案 1

    如果您想依赖模板,如您链接的帖子中所示,使用模板目录,您应该有不同的模板目录,每个目录都有其正确的info/exclude 文件,并使用

    git init -c --template=/path/to/template
    

    请注意,这不会创建 .gitignore 文件,而是创建 .git/info/exclude 文件,该文件保留在此 repo 的本地,并且在推送时不会共享(.gitignore 不是这种情况)

    解决方案 2

    如果您不想费心创建目录,而是从 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.shchmod +x,并将其放在你的路径中,然后你可以这样调用它:

    $ git init-more Perl
    

    【讨论】:

    • 你知道有没有可能
    • @ina 我想你忘了完成你的评论
    猜你喜欢
    • 2020-01-17
    • 1970-01-01
    • 2018-08-19
    • 2017-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-25
    • 1970-01-01
    相关资源
    最近更新 更多