每次用vim or gvim寫次寫完代碼的時(shí)候谚攒,項(xiàng)目中會(huì)多出很多*.swp文件鸡典,然后用git進(jìn)行版本控制的時(shí)候會(huì)不小心將這些文件加入版本庫腰耙,非常的討厭榛丢。
下面我們就一個(gè)例子,當(dāng)你用vim打開一個(gè)項(xiàng)目后挺庞,使用git status
查看晰赞,會(huì)發(fā)現(xiàn)下面的提示
# On branch source
# Your branch is ahead of 'origin/source' by 2 commits.
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .Gemfile.swp
nothing added to commit but untracked files present (use "git add" to track)
我們對(duì)項(xiàng)目明明沒有做任何的修改,卻多了一*.swp文件选侨。當(dāng)然有解決的辦法就是在每個(gè)項(xiàng)目中添加.gitignore文件掖鱼,但是這樣就非常麻煩每次要在各個(gè)項(xiàng)目中添加.gitignore文件并輸入 *.swp。
所以我們可以這樣做:新建~/.gitignore援制,輸入
.DS\_Store
*.swp
然后終端中執(zhí)行下列命令
$git config --global core.excludesfile ~/.gitignore
這樣git就會(huì)在任何項(xiàng)目中忽略*.swp文件了戏挡。
再次查看會(huì)出現(xiàn)下面提示
# On branch source
# Your branch is ahead of 'origin/source' by 2 commits.
#
nothing to commit (working directory clean)