.gitignore并没有忽略我的vim临时文件

时间:2014-05-16 20:19:49

标签: git vim

我的.gitignore文件存在问题。我做了我的研究并尝试了很多方法。保存我的.gitignore

时会发生以下步骤
git rm -rf --cached *.php.*
git add .
git status
git commmit -m "some message"

这是我的.gitignore文件的样子:

# Ignores anything that's a temp file created by vim
.*.s??
.*.*.s??

以下是应该跟踪的文件

# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .ajax.php.swn
#       .ajax.php.swo
#       .ajax.php.swp
#       .swervepay.php.swn
#       .swervepay.php.swo
#       .swervepay.php.swp
#       .swervepay_form.php.swm
#       .swervepay_form.php.swn
#       .swervepay_form.php.swp

我可以做些什么来阻止跟踪这些文件?每次我做一个git add。并提交推送,这些文件重新添加。任何帮助都会很棒。

1 个答案:

答案 0 :(得分:24)

使用标准规则

a handy repository on github for ignore rules代表Vim the rules are

# swap
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# session
Session.vim
# temporary
.netrwhist
*~
# auto-generated tag files
tags

使用这样的规则的最佳方法是put them in your global git ignore file

git config --global core.excludesfile ~/.gitignore

或者将交换文件放在其他地方

然而,这可能是一个更好的主意:

" ~/.vimrc file

" swap files (.swp) in a common location
" // means use the file's full path
set dir=~/.vim/_swap//

" backup files (~) in a common location if possible
set backup
set backupdir=~/.vim/_backup/,~/tmp,.

" turn on undo files, put them in a common location
set undofile
set undodir=~/.vim/_undo/

通过这种方式,vim不会用文件污染您的工作副本,忽略与否=)。