为git项目自动创建一个gitignore文件
444 字约 1 分钟
2024-12-01
使用git的时候,总是会为配置
.gitignore
苦恼【git GUI 程序这就要另说了:)】,很让人扫兴。但是这件事在最近有了转机,发现了一个自动生成.gitignore
文件的网站,看了看上面的文档,使用起来特别方便,只需要命令行就可以完成一个想要的.gitignore
文件。
命令行安装
Git
#!/bin/bash
$ git config --global alias.ignore '!gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; gi'
Linux
#!/bin/bash
$ echo "function gi() { curl -L -s https://www.gitignore.io/api/\$@ ;}" >> ~/.bashrc && source ~/.bashrc
#!/bin/zsh
$ echo "function gi() { curl -L -s https://www.gitignore.io/api/\$@ ;}" >> ~/.zshrc && source ~/.zshrc
#!/bin/fish
$ printf "function gi\n\tcurl -L -s https://www.gitignore.io/api/\$argv\nend\n" > ~/.config/fish/functions/gi.fish
macOS
#!/bin/bash
$ echo "function gi() { curl -L -s https://www.gitignore.io/api/\$@ ;}" >> ~/.bash_profile && source ~/.bash_profile
#!/bin/zsh
$ echo "function gi() { curl -L -s https://www.gitignore.io/api/\$@ ;}" >> ~/.zshrc && source ~/.zshrc
#!/bin/fish
$ 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
@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设置到全局
$ gi linux,eclipse >> ~/.gitignore_global
项目配置
为项目生成一个对应编程语言的.gitingore
文件,
$ gi java,python >> .gitignore