有些时候,你必须把某些文件放到Git工做目录中,但又不能提交它们,好比保存了数据库密码的配置文件啦,等等,每次git status
都会显示Untracked files ...
,有强迫症的童鞋内心确定不爽。git
好在Git考虑到了你们的感觉,这个问题解决起来也很简单,在Git工做区的根目录下建立一个特殊的.gitignore
文件,而后把要忽略的文件名填进去,Git就会自动忽略这些文件。github
不须要从头写.gitignore
文件,GitHub已经为咱们准备了各类配置文件,只须要组合一下就可使用了。全部配置文件能够直接在线浏览:https://github.com/github/gitignore数据库
忽略文件的原则是:fetch
.class
文件;有没有常常敲错命令?好比git status
?status
这个单词真心很差记。ui
若是敲git st
就表示git status
那就简单多了,固然这种偷懒的办法咱们是极力同意的。url
咱们只须要敲一行命令,告诉Git,之后st
就表示status
:操作系统
lwenhaodeMacBook-Pro:TestGit lwenhao$ git config --global alias.st status lwenhaodeMacBook-Pro:TestGit lwenhao$ git st On branch master Your branch is up to date with 'origin/master'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: README.md no changes added to commit (use "git add" and/or "git commit -a") lwenhaodeMacBook-Pro:TestGit lwenhao$
--global
参数是全局参数,也就是这些命令在这台电脑的全部Git仓库下都有用。code
配置Git的时候,加上--global
是针对当前用户起做用的,若是不加,那只针对当前的仓库起做用。orm
配置文件放哪了?每一个仓库的Git配置文件都放在.git/config
文件中:unicode
lwenhaodeMacBook-Pro:TestGit lwenhao$ cat .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [remote "origin"] url = https://github.com/liuwenhaoCN/TestGit.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [branch "dev"] remote = origin merge = refs/heads/dev lwenhaodeMacBook-Pro:TestGit lwenhao$
而当前用户的Git配置文件放在用户主目录下的一个隐藏文件.gitconfig
中:
lwenhaodeMacBook-Pro:TestGit lwenhao$ cd ~ lwenhaodeMacBook-Pro:~ lwenhao$ cat .gitconfig [user] name = lwenhao email = my@lwenhao.com [color] ui = true [alias] st = status lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit lwenhaodeMacBook-Pro:~ lwenhao$
配置别名也能够直接修改这个文件,若是改错了,能够删掉文件从新经过命令配置。