简体   繁体   English

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

[英]Sourcetree adding files in global .gitignore, not in repository .gitignore

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.当我将这些文件添加到 SourceTree 的“忽略文件”菜单中的忽略列表并检查本地 .gitignore 文件时,被忽略的文件没有在那里列出。 Instead these are listed in the global .gitignore.相反,这些列在全局 .gitignore 中。

How can I get SourceTree to add the files to the repository-specific .gitignore?如何让 SourceTree 将文件添加到特定于存储库的 .gitignore?

When you choose to ignore a file that is modified etc, SourceTree will bring up the following dialogue: 当您选择忽略已修改的文件等时,SourceTree将显示以下对话框:

忽略模态对话

Instead of choosing the "global ignore list", select the "this repository only" option. 不要选择“全局忽略列表”,而是选择“仅此存储库”选项。

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. 您可以通过转到Sourcetree - > Preferences - > Git菜单选项来删除它们。 See below. 见下文。 Sourcetree选项

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

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/ 中的全局忽略设置,因此我什至不需要更改它。

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解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM