为git项目自动创建一个gitignore文件

使用git的时候,总是会为配置 .gitignore 苦恼【git GUI 程序这就要另说了:)】,很让人扫兴。但是这件事在最近有了转机,发现了一个自动生成.gitignore文件的网站,看了看上面的文档,使用起来特别方便,只需要命令行就可以完成一个想要的 .gitignore 文件。

命令行安装

Git

#!/bin/bash

1
$ git config --global alias.ignore '!gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; gi'

Linux

#!/bin/bash

1
$ echo "function gi() { curl -L -s https://www.gitignore.io/api/\$@ ;}" >> ~/.bashrc && source ~/.bashrc

#!/bin/zsh

1
$ echo "function gi() { curl -L -s https://www.gitignore.io/api/\$@ ;}" >> ~/.zshrc && source ~/.zshrc

#!/bin/fish

1
$ printf "function gi\n\tcurl -L -s https://www.gitignore.io/api/\$argv\nend\n" > ~/.config/fish/functions/gi.fish

macOS

#!/bin/bash

1
$ echo "function gi() { curl -L -s https://www.gitignore.io/api/\$@ ;}" >> ~/.bash_profile && source ~/.bash_profile

#!/bin/zsh

1
$ echo "function gi() { curl -L -s https://www.gitignore.io/api/\$@ ;}" >> ~/.zshrc && source ~/.zshrc

#!/bin/fish

1
$ printf "function gi\n\tcurl -L -s https://www.gitignore.io/api/\$argv\nend\n" > ~/.config/fish/functions/gi.fish

windows

在Git安装目录中的cmd中,创建一个gi.cmd文件,写入一下内容,并将此文件cmd路径加入到环境变量中的PATH

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@rem Do not use "echo off" to not affect any child calls.
@setlocal

@rem Get the abolute path to the parent directory, which is assumed to be the
@rem Git installation root.
@for /F "delims=" %%I in ("%~dp0..") do @set git_install_root=%%~fI
@for /F "delims=" %%I in ("%~dp0..") do @set git_mingw_root=%%~fI\mingw
@if not exist "%git_mingw_root%" @set git_mingw_root=%git_install_root%\mingw64
@set PATH=%git_install_root%\bin;%git_mingw_root%\bin;%PATH%

@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
@if not exist "%HOME%" @set HOME=%USERPROFILE%

@curl.exe -L -s https://www.gitignore.io/api/%*

使用

全局配置

附加操作系统和IDE设置到全局

1
$ gi linux,eclipse >> ~/.gitignore_global

项目配置

为项目生成一个对应编程语言的.gitingore文件,

1
$ gi java,python >> .gitignore

【注意:因为不能保证所有的系统都可以使用,如果存在不能使用的情况,请进入github项目,看官方配置】

This blog is under a CC BY-NC-SA 3.0 Unported License
本文链接:https://blog.suixin.kim/2016/12/07/gitignore-auto/