如何创建/添加.git / info / exclude文件以在本地忽略文件?

时间:2017-04-24 16:47:32

标签: git github gitignore

我还在学习git并掌握它。我想在本地忽略文件到我的工作流程。我在这里阅读了许多Q& As以及git文档,但它们都没有提及或解释如何创建和访问.git/info/exclude文件以进行修改。当我调用ls -la命令查看本地存储库中的所有隐藏文件时,我没有该文件或者至少它不在git的根目录中。我只看到.git.gitignore以及存储库中看到的其他文件。

每次编辑文件并暂存时,都会有其他系统文件一直显示为已修改。我每次都必须存储它以便能够提交/推送到远程存储库。

我尝试过使用像nano .git/info/excludecat .git/info/exclude这样的命令,假设我必须创建一个让它工作的命令,但它会说Error: No such file or directory。那么,如何访问该文件以开始在本地忽略它们,以使我的工作流程更容易,更少繁琐?

另外,我运行了命令cd .git,我看到.git目录中的一些文件(但没有info/exclude文件夹):

enter image description here

注意:我知道git update-index --assume-unchanged <file>git update-index --skip-worktree <file>是在本地忽略文件的其他方法,但我有兴趣知道如何使用{{1}方式。

1 个答案:

答案 0 :(得分:6)

A couple things:

First, you most likely want to use .gitignore instead of .git/info/exclude. It does the same thing, except it gets checked into the repo and versioned along with all the working files. In most situations this would be the desired behavior.

(If you use .git/info/exclude then only that particular clone of the repository will ignore the specified paths, and if the ignore rules change as your code evolves, then you won't have a way to keep track of which rules go with which version of your code.)

But if you really do want to use .git/info/exclude... well, you're treating it like that's a single file name, but (per *NIX conventions, which prevail through most git docs) the / is a path separator. So in your repo you see .git. Then

cd .git

and if you do an ls there you might see info. If not

mkdir info

Then you can cd info and create the file exclude