让git忽略vim在所有目录中生成的临时文件的正确方法是什么(无论是跨系统全局的还是单个项目的本地的)?
当前回答
这应该只针对每个用户进行,而不是针对每个存储库。如果Joe使用emacs,他希望忽略emacs备份文件,但是Betty(她使用vi)希望忽略vi备份文件(在许多情况下,它们是相似的,但是存在大约24,893个常见的编辑器,试图忽略所有不同的备份扩展名是非常荒谬的)。
换句话说,不要把任何东西放在。gitignore或core中。在$GIT_DIR/config中排除。把信息放在$HOME/。改用Gitconfig(如nonopolonia建议的使用——global。)注意,“全局”指的是每个用户,而不是每个系统。
如果您希望为所有用户在整个系统中进行配置(实际上并不是这样),那么您将需要一种不同的机制。(可能在初始化存储库之前设置模板。)
其他回答
这应该只针对每个用户进行,而不是针对每个存储库。如果Joe使用emacs,他希望忽略emacs备份文件,但是Betty(她使用vi)希望忽略vi备份文件(在许多情况下,它们是相似的,但是存在大约24,893个常见的编辑器,试图忽略所有不同的备份扩展名是非常荒谬的)。
换句话说,不要把任何东西放在。gitignore或core中。在$GIT_DIR/config中排除。把信息放在$HOME/。改用Gitconfig(如nonopolonia建议的使用——global。)注意,“全局”指的是每个用户,而不是每个系统。
如果您希望为所有用户在整个系统中进行配置(实际上并不是这样),那么您将需要一种不同的机制。(可能在初始化存储库之前设置模板。)
# VIM: Temperory files
*~
# VIM: Swap-files
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# VIM: Commands :cs, :ctags
tags
cscope.*
# VIM session
Session.vim
# VIM: netrw.vim: Network oriented reading, writing, browsing (eg: ftp scp)
.netrwhist
The name of the swap file is normally the same as the file you are editing, with the extension ".swp". On Unix, a '.' is prepended to swap file names in the same directory as the edited file. This avoids that the swap file shows up in a directory listing. On MS-DOS machines and when the 'shortname' option is on, any '.' in the original file name is replaced with '_'. If this file already exists (e.g., when you are recovering from a crash) a warning is given and another extension is used, ".swo", ".swn", etc. An existing file will never be overwritten. The swap file is deleted as soon as Vim stops editing the file. The replacement of '.' with '_' is done to avoid problems with MS-DOS compatible filesystems (e.g., crossdos, multidos).
http://vimdoc.sourceforge.net/htmldoc/recover.html
http://www.vim.org/scripts/script.php?script_id=1075
肯定的是,
只需要创建一个“。Gitignore”在项目的主目录上 并且必须控制
*.swp
就是这样
在一个命令中
project-home-directory$ echo '*.swp' >> .gitignore
我还建议忽略以下文件:
.*.swp
.*.swo
因为您可能有以.swp结尾的文件
下面是生成交换文件扩展名的实际VIM代码:
/*
* Change the ".swp" extension to find another file that can be used.
* First decrement the last char: ".swo", ".swn", etc.
* If that still isn't enough decrement the last but one char: ".svz"
* Can happen when editing many "No Name" buffers.
*/
if (fname[n - 1] == 'a') /* ".s?a" */
{
if (fname[n - 2] == 'a') /* ".saa": tried enough, give up */
{
EMSG(_("E326: Too many swap files found"));
vim_free(fname);
fname = NULL;
break;
}
--fname[n - 2]; /* ".svz", ".suz", etc. */
fname[n - 1] = 'z' + 1;
}
--fname[n - 1]; /* ".swo", ".swn", etc. */
这将生成如下格式的交换文件:
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
这几乎是包括在github自己的gitignore文件VIM。
正如其他人所正确指出的那样,这个.gitignore也会忽略.svg图像文件和.swf adobe flash文件。
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 在Vim中如何从“gf”返回
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式