要求在 GitHub 中推送被忽略的文件

问题描述

我在 GitHub.com 中有存储库。对于推和拉,我使用可视化工具 Github Desktop。最近我在 Github.com 中创建了一个存储库来存储 .NET Core API 项目。我创建了一个 git ignore 文件,指示哪些文件不应该提示推送。 git ignore 文件如下:

Source/.vs/*
Source/Libraries/Common/bin/*
Source/Libraries/Common/obj/*
Source/Libraries/Data/bin/*
Source/Libraries/Data/obj/*
Source/Libraries/Domains/bin/*
Source/Libraries/Domains/obj/*
Source/Libraries/Services/bin/*
Source/Libraries/Services/obj/*

但是每次我在 Visual Studio 2019 中构建项目时,以下文件都会提示推送,尽管它们包含在 git ignore 中不提示提示文件列表如下:

Source/Libraries/Common/bin/Debug/netcoreapp3.1/Common.dll
Source/Libraries/Common/bin/Debug/netcoreapp3.1/Common.dll
Source/Libraries/Common/bin/Debug/netcoreapp3.1/Common.pdb
Source/Libraries/Common/obj/Debug/netcoreapp3.1/Common.csproj.FileListAbsolute.txt
Source/Libraries/Common/obj/Debug/netcoreapp3.1/Common.csprojAssemblyReference.cache
Source/Libraries/Common/obj/Debug/netcoreapp3.1/Common.dll
Source/Libraries/Common/obj/Debug/netcoreapp3.1/Common.pdb
Source/Libraries/Data/bin/Debug/netcoreapp3.1/Data.dll
Source/Libraries/Data/bin/Debug/netcoreapp3.1/Data.pdb
Source/Libraries/Data/obj/Debug/netcoreapp3.1/Data.csproj.FileListAbsolute.txt
Source/Libraries/Data/obj/Debug/netcoreapp3.1/Data.csprojAssemblyReference.cache
Source/Libraries/Data/obj/Debug/netcoreapp3.1/Data.dll
Source/Libraries/Data/obj/Debug/netcoreapp3.1/Data.pdb
Source/Libraries/Domains/obj/Debug/netcoreapp3.1/Domains.csproj.FileListAbsolute.txt
Source/Libraries/Domains/obj/Debug/netcoreapp3.1/Domains.csprojAssemblyReference.cache
Source/Libraries/Services/obj/Debug/netcoreapp3.1/Services.csproj.FileListAbsolute.txt
Source/Libraries/Services/obj/Debug/netcoreapp3.1/Services.csprojAssemblyReference.cache
Source/Web/obj/Debug/netcoreapp3.1/Web.csproj.FileListAbsolute.txt
Source/Web/obj/Debug/netcoreapp3.1/Web.csprojAssemblyReference.cache
Source/.vs/CashFlow/v16/.suo
Source/.vs/CashFlow/v16/.suo
Source/Libraries/Common/bin/Debug/netcoreapp3.1/Common.dll
Source/Libraries/Common/bin/Debug/netcoreapp3.1/Common.pdb
Source/Libraries/Common/obj/Debug/netcoreapp3.1/Common.csproj.FileListAbsolute.txt
Source/Libraries/Common/obj/Debug/netcoreapp3.1/Common.csprojAssemblyReference.cache
Source/Libraries/Common/obj/Debug/netcoreapp3.1/Common.dll
Source/Libraries/Common/obj/Debug/netcoreapp3.1/Common.pdb
Source/Libraries/Data/bin/Debug/netcoreapp3.1/Data.dll
Source/Libraries/Data/bin/Debug/netcoreapp3.1/Data.pdb
Source/Libraries/Data/obj/Debug/netcoreapp3.1/Data.csproj.FileListAbsolute.txt
Source/Libraries/Data/obj/Debug/netcoreapp3.1/Data.csprojAssemblyReference.cache
Source/Libraries/Data/obj/Debug/netcoreapp3.1/Data.dll
Source/Libraries/Data/obj/Debug/netcoreapp3.1/Data.pdb
Source/Libraries/Domains/obj/Debug/netcoreapp3.1/Domains.csproj.FileListAbsolute.txt
Source/Libraries/Domains/obj/Debug/netcoreapp3.1/Domains.csprojAssemblyReference.cache
Source/Libraries/Services/obj/Debug/netcoreapp3.1/Services.csproj.FileListAbsolute.txt
Source/Libraries/Services/obj/Debug/netcoreapp3.1/Services.csprojAssemblyReference.cache
Source/Web/obj/Debug/netcoreapp3.1/Web.csprojAssemblyReference.cache

gitignore 文件的位置如下:

enter image description here

谁能帮我解决这个问题。

解决方法

您尚未添加所有子目录。例如,您的 .gitignore 应如下所示。

Source/.vs/*
Source/Libraries/Common/bin/*
Source/Libraries/Common/obj/*
Source/Libraries/Data/bin/*
Source/Libraries/Data/obj/*
Source/Libraries/Domains/bin/*
Source/Libraries/Domains/obj/*
Source/Libraries/Services/bin/*
Source/Libraries/Services/obj/*
# new lines:
Source/Libraries/Common/bin/Debug/*
Source/Libraries/Common/bin/Debug/netcoreapp3.1/*
Source/Libraries/Common/obj/Debug/*
Source/Libraries/Common/obj/Debug/netcoreapp3.1/*
Source/Libraries/Data/bin/Debug/*
Source/Libraries/Data/bin/Debug/netcoreapp3.1/*

并添加构建显示它正在添加的所有其他文件夹,而不是我开始做的文件。 使用星号添加所有内容不会添加子目录。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...