git 如何git忽略存储库中任何地方的ipython笔记本检查点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35916658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:59:52  来源:igfitidea点击:

How to git ignore ipython notebook checkpoints anywhere in repository

gitcommitgitignorejupyter-notebook

提问by sapo_cosmico

This is mostly a git question. I want to commit my ipython notebooks but gitignore the checkpoints.

这主要是一个 git 问题。我想提交我的 ipython 笔记本,但 gitignore 检查点。

The repo has multiple folders which each have ipython notebooks, therefore just ignoring a single directory does not solve it. I want to keep adding new folders with notebooks inside without worrying about it.

存储库有多个文件夹,每个文件夹都有 ipython 笔记本,因此仅忽略单个目录并不能解决问题。我想继续添加带有笔记本的新文件夹而不必担心。

My hunch is that there must be a way to use some wildcard to gitignore anything that is in a folder that is called */.ipynb_checkpoints/but haven't been able to figure it out.

我的预感是,必须有一种方法可以使用通配符来忽略名为 */.ipynb_checkpoints/但无法弄清楚的文件夹中的任何内容

So, how can I git ignore all ipython notebook checkpoints in a repository, wherever they are?

那么,我如何 git 忽略存储库中的所有 ipython notebook 检查点,无论它们在哪里?

回答by minrk

If you add to .gitignore:

如果添加到 .gitignore:

.ipynb_checkpoints

(no slashes anywhere), any file or directory in the repo with that name will be ignored. Paths are only checked if you include /.

(任何地方都没有斜线),存储库中具有该名称的任何文件或目录都将被忽略。仅当您包含/.

From this answeryou can also have a global gitignore for your computer:

这个答案中,您还可以为您的计算机设置全局 gitignore:

git config --global core.excludesfile '~/.gitignore'
echo '.ipynb_checkpoints' >> ~/.gitignore

回答by Anton Karazeev

I would recommend to use **/*.ipynb_checkpoints/in your .gitignorefile.

我建议**/*.ipynb_checkpoints/在您的.gitignore文件中使用。

回答by djwbrown

Add to your .gitignore:

添加到您的.gitignore

.ipynb_checkpoints
*/.ipynb_checkpoints/*

And you should be good to go.

你应该很高兴去。

回答by Merlin

This works.

这有效。

Folder/.ipynb_checkpoints/*.ipynb

回答by Alexander

Some times you may forget that you are already tracking the file in your git repository (as it was in my case). So you may have to untrack it first

有时您可能会忘记您已经在跟踪 git 存储库中的文件(就像我的情况一样)。所以你可能必须先取消跟踪它

git rm --cached Folder_with_ipynb/.ipynb_checkpoints/news-checkpoint.ipynb

and then add to your .gitignorethe line:

然后添加到您.gitignore的行中:

*/.ipynb_checkpoints/*.ipynb

回答by Sahar Nasser

I used the command rm -rf .ipynb_checkpoints. This worked for me.

我使用了命令rm -rf .ipynb_checkpoints。这对我有用。

回答by Engineero

For some reason, none of the current answers worked for me. I was eventually able to get git to ignore all of my checkpoint files (and any other unwanted hidden files and folders) by adding:

出于某种原因,目前的答案都不适合我。通过添加以下内容,我最终能够让 git 忽略所有检查点文件(以及任何其他不需要的隐藏文件和文件夹):

.*  # ignore all hidden files and folders
!/.gitignore  # explicitly do not ignore .gitignore

to my .gitignorefile in the repo's base directory. This is a broad sweep, and will be a pain to maintain if you want to keep hidden files in your repo, but I have no need for any except my .gitignore, so it works for me!

到我.gitignore在 repo 的基本目录中的文件。这是一个广泛的扫描,如果你想在你的仓库中保留隐藏文件,维护起来会很痛苦,但除了 my 之外我不需要任何文件.gitignore,所以它对我有用!