首页 > 解决方案 > 要求在 GitHub 中推送被忽略的文件

问题描述

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

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 文件的位置如下: 在此处输入图像描述

谁能帮我解决这个问题。

标签: gitgithubgithub-desktop

解决方案


您尚未添加所有子目录。例如,您的 .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/*

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


推荐阅读