简体   繁体   English

gitignore文件无法正常工作

[英]gitignore file is not working properly

Extract of ".gitignore" file 提取“ .gitignore”文件

/Api/bin/log4net.dll
/Web/bin/log4net.dll
/Api/bin/System.Web.Http.dll
/Api/bin/System.Net.Http.Formatting.dll
/packages

When I try to commit : 当我尝试提交时:

在此处输入图片说明

Question : How to get rid of these repackage files when I try to commit (.gitignore is in root )? 问题:当我尝试提交时,如何摆脱这些重新打包文件(.gitignore在root中)?

Step 1 : Firstly commit any outstanding code changes into your local master. 步骤1:首先将所有未完成的代码更改提交到本地主机。

Type below commands on Git Bash. Git Bash上键入以下命令

Step 2 : Move into your local repository directory (The root where your .gitignore file resides). 第2步:移动到本地存储库目录(.gitignore文件所在的根)。

cd "D:\Freelance Work\My Mvc Project"

Step 3 : 第三步:

git rm -r --cached .

This removes any changed files from the index(staging area). 这将从索引(临时区域)中删除所有更改的文件。

Step 4 : 第四步 :

git add .

Step 5 : Commit it. 步骤5:提交。

git commit -m ".gitignore is now working"

You might have those files committed before you add the lines in gitignore. 在gitignore中添加行之前,可能已经提交了那些文件。

If that's the case, you have to remove them from tracking. 如果是这种情况,则必须将其从跟踪中删除。

If you are using windows, cd to the path of your local git. 如果您使用的是Windows,请cd到本地git的路径。 For example if your git repo folder is in c:\\project\\projectA, you should type 例如,如果您的git repo文件夹位于c:\\ project \\ projectA中,则应键入

cd /c/project/projectA

Then you have to untrack those file one by one by the below command: 然后,您必须通过以下命令逐一取消跟踪这些文件:

git rm Api/bin/log4net.dll

After you remove them all, you have to commit. 全部删除之后,您必须提交。

If the files were already checked in, then you need to remove them before git will start ignoring them. 如果文件已经签入,那么您需要先删除它们,然后git才会开始忽略它们。 See if the files are listed when you run git ls-files . 查看在运行git ls-files时是否列出了git ls-files If they are, then see the SO answer that has been suggested as a possible duplicate of your question 如果是这样,则请参阅建议的SO答案,该答案可能与您的问题重复

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

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