git Sourcetree 在全局 .gitignore 中添加文件,而不是在存储库 .gitignore 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30907829/
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:19:13  来源:igfitidea点击:

Sourcetree adding files in global .gitignore, not in repository .gitignore

gitgitignoreatlassian-sourcetree

提问by Irfan DANISH

I am using SourceTree for my GIT repositories.

我正在将 SourceTree 用于我的 GIT 存储库。

Today I need to ignore some files; when I added these files to ignore list from SourceTree's "Ignore file" menu and check local .gitignore file, the ignored files are not listed there. Instead these are listed in the global .gitignore.

今天我需要忽略一些文件;当我将这些文件添加到 SourceTree 的“忽略文件”菜单中的忽略列表并检查本地 .gitignore 文件时,被忽略的文件没有在那里列出。相反,这些列在全局 .gitignore 中。

How can I get SourceTree to add the files to the repository-specific .gitignore?

如何让 SourceTree 将文件添加到特定于存储库的 .gitignore?

回答by acanby

When you choose to ignore a file that is modified etc, SourceTree will bring up the following dialogue:

当您选择忽略修改等的文件时,SourceTree 会弹出以下对话框:

Ignore modal dialogue

忽略模态对话

Instead of choosing the "global ignore list", select the "this repository only" option.

不要选择“全局忽略列表”,而是选择“仅此存储库”选项。

回答by UKDataGeek

Easiest way to edit the individual, is right click the file. Click Ignore and select the option to ignore just in this repository then you will see a new file called .gitignore in the list.

编辑个人的最简单方法是右键单击文件。单击忽略并选择仅在此存储库中忽略的选项,然后您将在列表中看到一个名为 .gitignore 的新文件。

If you have accidentally already added them to the list. You can delete them by going to Sourcetree - > Preferences -> Git menu option. See below. Sourcetree options

如果您不小心已经将它们添加到列表中。您可以通过转到 Sourcetree -> Preferences -> Git 菜单选项来删除它们。见下文。 源树选项

As a quick tip - I find that github has a great selection of starter github ignore files which I find really useful to start a new project

作为一个快速提示 - 我发现 github 有很多启动 github 忽略文件的选择,我发现这些文件对于开始一个新项目非常有用

Eg: https://github.com/github/gitignore

例如:https: //github.com/github/gitignore

回答by Greg7000

In my case, at some point in time, Sourcetree started using the gitconfig from C:\Program Files\Git\mingw64\etc\gitconfig instead of using C:\Users\yourUser.gitconfig.

就我而言,在某个时间点,Sourcetree 开始使用来自 C:\Program Files\Git\mingw64\etc\gitconfig 的 gitconfig,而不是使用 C:\Users\yourUser.gitconfig。

Once I added the following line in this gitconfig, it resolved my issue on Sourcetree:

在此 gitconfig 中添加以下行后,它解决了我在 Sourcetree 上的问题:

[core]
    safecrlf = false
    excludesfile = C:\Users\<YOUR_USER>\Documents\gitignore_global.txt

Please note that on my side the global ignore setting from Tools/Option/Git/ does not seemed to be considered by Sourcetree, therefore I don't even need to change it.

请注意,在我这边,Sourcetree 似乎并未考虑 Tools/Option/Git/ 中的全局忽略设置,因此我什至不需要更改它。

回答by Thar

I had the opposite issue, local worked but global did not work, for that you also need to create the global ignore file by running the command line

我遇到了相反的问题,本地工作但全局不起作用,为此您还需要通过运行命令行来创建全局忽略文件

git config --global core.excludesfile ~/.gitignore_global

Else source tree will not save this in the preferences.

否则源树不会将其保存在首选项中。

Then follow the acanby solution.

然后按照 acanby 解决方案。