如何让git跟踪所有以“〜”结尾的文件? [英] How to keep git from tracking all files that end with a "~"?

查看:163
本文介绍了如何让git跟踪所有以“〜”结尾的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Gedit,并且每次保存文件时,Gedit都会创建它的副本,并且副本的名称始终以〜结尾。问题是,Git总是试图追踪这些文件,而我不想那么做!有没有办法仍然可以使用 git add。,但只添加那些不以〜结尾的文件?

解决方案

你想要一个 gitignore文件

如果您想要以波浪号结束所有内容(应该是安全的;我无法想象合理的使用情况),请确保以下行位于您的repo文件夹层次结构顶部的 .gitignore 文件中:

   






如果你 >还希望摆脱那些围绕在本地文件系统中的波浪文件,你可以。最好让Gedit将其备份文件放在别的地方。 JEdi​​t和VIm是我使用最多的两位编辑,拥有这样的设置,而且它更加清洁那些加载gitignore的地方。



不幸的是,Gedit没有这个选项。最好的办法是关闭备份。 在您担心之前,最糟糕的情况是您在保存后立即丢失文件中的内容。这不是最坏的情况 - 这就是为什么你在git仓库中得到这个,对吧?



注意:如果你想在本地保留后缀文件,请执行。上面设置的.gitignore会让你不小心分享它们。



您可以关闭像这样的后缀备份< a>


为了防止Gedit将来创建这些备份,请打开Gedit,打开Preferences对话框(Edit> Preferences),选择编辑器选项卡,删除保存前创建文件的备份副本选项中的选中项,然后单击关闭。做完这些之后,Gedit将不再使用替代品进行备份。



I'm using Gedit, and each time I save a file, Gedit creates a copy of it, and the name of the copy always ends with a ~. The problem is, Git always tries to track these files, and I don't want that! Is there a way to still be able to use git add ., but add just those files that do not end with ~?

You want a gitignore file.

If you want to nuke everything that ends with a tilde (which should be safe; I can't imagine a reasonable use-case where that's bad), make sure the following line is in your .gitignore file at the top of your repo's folder hierarchy:

*~


If you also want to get rid of those tilde files laying around in your local file system, you can. It'd be best to make Gedit put its backup files somewhere else. JEdit and VIm, the two editors I use most, have such settings, and it's lots cleaner to keep those somewhere else than loading up gitignore.

Unfortunately, Gedit doesn't have that option. The best it can do is to turn off the ~ backups. Before you get worried, the worst case is that you lose what was in the file immediately before you saved. That's not a worst-case -- that's why you've got this in a git repo, right?

NOTE: If you want to keep the ~ suffixed files locally, do. The .gitignore you set up, above, will keep you from accidentally sharing them.

You can turn off ~ suffixed backups like this

To prevent Gedit from creating these backups in the future, open up Gedit, open up the Preferences dialog (Edit > Preferences), select the Editor tab, remove the check in the "Create a backup copy of files before saving" option, and click Close. After doing this, Gedit will no longer make the backups with tildes all over the place.

这篇关于如何让git跟踪所有以“〜”结尾的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆