有些時候,你必須把某些文件放到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$
配置別名也能夠直接修改這個文件,若是改錯了,能夠刪掉文件從新經過命令配置。