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

jam*_*dri 8 git vim

我的.gitignore文件有问题.我做了我的研究并尝试了很多方法.当我保存我的.gitignore时,会发生以下步骤

git rm -rf --cached *.php.*
git add .
git status
git commmit -m "some message"
Run Code Online (Sandbox Code Playgroud)

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

# Ignores anything that's a temp file created by vim
.*.s??
.*.*.s??
Run Code Online (Sandbox Code Playgroud)

以下是应该保持跟踪的文件

# 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
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能阻止这些文件被跟踪?每次我做一个git add.并提交推送,这些文件重新添加.任何帮助都会很棒.

AD7*_*six 25

使用标准规则

对于忽略规则,github上一个方便的存储库,对于Vim,规则是:

# swap
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# session
Session.vim
# temporary
.netrwhist
*~
# auto-generated tag files
tags
Run Code Online (Sandbox Code Playgroud)

使用这样的规则的最佳方法是将它们放在全局git ignore文件中:

git config --global core.excludesfile ~/.gitignore
Run Code Online (Sandbox Code Playgroud)

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

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

" ~/.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/
Run Code Online (Sandbox Code Playgroud)

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