1.使用alias可以使执行git命令更加快速。
将下面的文件以.gitconfig为文件名存在家目录下。【注意最后的username与email换成自己的】
[alias]
l = log --color --graph --decorate --pretty=oneline --abbrev-commit
l0 = log --color --graph -- decorate --pretty=oneline --abbrev-commit -U0
la = log --color --graph --decorate --pretty=oneline --abbrev-commit --all
lb = log --color --graph --decorate --pretty=oneline --abbrev-commit --all --simplify-by-decoration
lg = log --color --graph --decorate
dl = log --date-order --color --graph --decorate --pretty=oneline --abbrev-commit
dla = log --date-order --color --graph --decorate --pretty=oneline --abbrev-commit --all
dlb = log --date-order --color --graph --decorate --pretty=oneline --abbrev-commit --all --simplify-by-decoration
dig = log --date-order --color --graph --decorate
d = diff --color
dc = diff --color --cached
d0 = diff --color --unified=0
ci = commit --verbose
co = checkout
tr = checkout --track
s = status --short
st = status
br = branch
[user]
name = ****
email = ****@***.***
2. 实现分支的自动补齐。
在命令行里写git命令的时候,每次输入分支名会比较慢,通过下面的配置可以像在查看文件时那样,按tab键自动补全文件名。
mac
curl https://github.com/git/git/raw/master/contrib/completion/git-completion.bash -OL
cp git-completion.bash ~/.git-completion.bash
*然后在~/.bash_profile目录下增加一句:*
source ~/.git-completion.bash
如果上面失败的话, 有时候我会遇到错误的情况,但是一般上面的是没有问题的.
如果$BASH_VERSION > 3: brew install bash-completion@2 (更新版本)
添加到.bash_profile:
if [ -f /usr/local/share/bash-completion/bash_completion ]; then
. /usr/local/share/bash-completion/bash_completion
fi
对于早期版本的 bash: brew install bash-completion
添加到.bash_profile:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
ubuntu
在大多数发行版中, git 完成脚本安装到/etc/bash_completion.d/(或者/usr/share/bash-completion/completions/completions/git)
也就是说,apt-get install git 时就大多数发行版, 都已经自动把自动补全的脚本放在上面的路径了.
不需要去 github在下载。只需要把下面的命令添加到.bashrc:
source /etc/bash_completion.d/git
# or 具体看命令在哪里,cat一下就知道了
source /usr/share/bash-completion/completions/git
在 Ubuntu 的某些版本中, git 自动完成功能可能会在默认情况下被破坏, 比如说找不到自动补全的脚本之类的
通过运行此命令重新安装将会修复它:
sudo apt-get install git-core bash-completion
即可。
3. 设置git忽略版本控制目录里指定的文件
在代码库根目录下新建一个名为.gitignore的文件,然后可以通过向其中写入下面的规则将文件或目录排除在版本控制之外:
# 以'#'开始的行,被视为注释.
# 忽略gitignore文件自身
.gitignore
# 忽略.idea目录,常见于各种ide环境,如phpstorm
.idea
# 忽略掉所有文件名是 foo.txt的文件.
foo.txt
# 忽略所有生成的 html文件,
*.html
# foo.html是手工维护的,所以例外.
!foo.html
# 忽略所有.o和 .a文件.
*.[oa]