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

标签 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 。并 promise 向上推,这些文件将被重新添加。任何帮助都将不胜感激。

最佳答案

使用标准规则

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 就不会用文件污染你的工作副本,忽略或不=)。

关于git - .gitignore 没有忽略我的 vim 临时文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23703923/

相关文章:

git - 克隆另一个名称的Git存储库

vim - 在 vim 中调用 script-local 函数出现错误?

vim - 如何将文件的总行数添加到vim状态栏

git - 在 cygwin 中调用 git commit 时 vim 不工作

vim - 在 Vim 上使用 NERDTree 重命名或复制文件和文件夹。是否可以?

git - 克隆git repo的子树/子目录

git - 推/pull git 时出现错误

python - 尝试解析标签时德威治的 NotCommitError

android - 如何将 bitbucket 私有(private) Git 存储库添加到 AOSP?

vim - Emacs 'Ctrl+s Ctrl+w' 在 Vim 中等效