Git — 自定義Git

設置命令輸出顏色

執行 git config --global color.ui true 命令設置命令輸出顏色:

$ git config --global color.ui true
忽略特殊文件

在 Git 工作目錄中,但又不想提交的文件;可以通過一個特殊的 .gitignore 文件,將要忽略的文件名填入,Git 就會自動忽略這些文件。

忽略文件的原則:

  1. 忽略操作系統自動生成的文件,比如縮略圖等;
  2. 忽略編譯生成的中間文件、可執行文件等;例如一個文件通過另一個文件自動生成的,那自動生成的文件將不必要放進版本庫,比如Java編譯產生的 .class 文件;
  3. 忽略自己的帶有敏感信息的配置文件,比如存放口令的配置文件。

當向 git 添加不進去文件,說明文件被 .gitignore 忽略:

$ git add App.class
The following paths are ignored by one of your .gitignore files:
App.class
Use -f if you really want to add them.

可以執行 git add -f 命令強制添加:

$ git add -f App.class

執行 git check-ignore -v 命令檢查 .gitignore 的規則:

$ git check-ignore -v App.class
.gitignore:3:*.class	App.class
配置別名

避免命令輸入出錯,可以通過配置別名簡化;
執行 git config --global alias 命令設置別名:

$ git config --global alias.st status

注意–global 參數是全局參數,既是這些命令該機器的所有Git倉庫下都有用。

配置文件

配置信息放在 .git/config 文件中:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = [email protected]:michaelliao/learngit.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[alias]
    last = log -1
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章