我的 .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/