将新创建的特定文件夹添加到 Git 中的 .gitignore
我有一个干净的工作目录,并于昨晚从 Git 存储库中引入了一个克隆。 但现在我的本地服务器创建并包含一个我想忽略的统计文件夹。
当我运行 git status 时,我似乎无法让 Git 忽略这个文件夹。
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: app_public/views/pages/privacy.php
new file: app_public/views/pages/terms.php
new file: public_html/stats/ctry_usage_200908.png
new file: public_html/stats/daily_usage_200908.png
new file: public_html/stats/dns_cache.db
new file: public_html/stats/hourly_usage_200908.png
new file: public_html/stats/index.html
new file: public_html/stats/usage.png
new file: public_html/stats/usage_200908.html
new file: public_html/stats/webalizer.current
new file: public_html/stats/webalizer.hist
Changed but not updated:
modified: .gitignore
我在 .gitignore 中添加了几行不同的行,但它仍在尝试添加它们:
public_html/stats
public_html/stats/**
public_html/stats/**/*
public_html/stats/*
I had a clean working directory and brought in a clone from a Git repo last night.
But now my local server created and contains a stats folder which I want to ignore.
I can't seem to get Git to ignore this folder when I run a git status.
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: app_public/views/pages/privacy.php
new file: app_public/views/pages/terms.php
new file: public_html/stats/ctry_usage_200908.png
new file: public_html/stats/daily_usage_200908.png
new file: public_html/stats/dns_cache.db
new file: public_html/stats/hourly_usage_200908.png
new file: public_html/stats/index.html
new file: public_html/stats/usage.png
new file: public_html/stats/usage_200908.html
new file: public_html/stats/webalizer.current
new file: public_html/stats/webalizer.hist
Changed but not updated:
modified: .gitignore
I added in my .gitignore a few different lines but it still trying to add them:
public_html/stats
public_html/stats/**
public_html/stats/**/*
public_html/stats/*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对于这种情况,有两种情况
情况 1: 文件已添加到 git 存储库。
情况 2: 新创建的文件,使用时其状态仍显示为未跟踪文件
如果您有情况 1:
步骤 1:
然后运行
将其从 git repo 缓存中删除
(如果它是一个目录),然后使用
步骤 2: 如果情况 1 结束,则创建名为
.gitignore 的新文件code> 在 git 存储库中
第 3 步: 使用以下命令告诉 git 忽略/假设文件未更改
第 4 步: 现在,使用 git status open
检查状态。 gitignore
在你的编辑器 nano、vim、geany 等任何一个中,添加要忽略的文件/文件夹的路径。如果是文件夹,则使用folder_name/*
忽略所有文件。如果您仍然不明白,请阅读文章 git 忽略文件 链接。
For this there are two cases
Case 1: File already added to git repo.
Case 2: File newly created and its status still showing as untracked file when using
If you have case 1:
STEP 1:
Then run
to remove it from git repo cache
if it is a directory then use
STEP 2: If Case 1 is over then create new file named
.gitignore
in your git repoSTEP 3: Use following to tell git to ignore / assume file is unchanged
STEP 4: Now, check status using git status open
.gitignore
in your editor nano, vim, geany etc... any one, add the path of the file / folder to ignore. If it is a folder then userfolder_name/*
to ignore all file.If you still do not understand read the article git ignore file link.
尝试
/public_html/stats/*
吗?但由于
git status
中的文件报告为待提交,这意味着您已经手动添加了它们。当然,在这种情况下,忽视就有点太晚了。您可以git rm --cache
它们(IIRC)。Try
/public_html/stats/*
?But since the files in
git status
reported as to be commited that means you've already added them manually. In which case, of course, it's a bit too late to ignore. You cangit rm --cache
them (IIRC).从“git helpignore”中我们了解到:
因此你需要的是
From "git help ignore" we learn:
Therefore what you need is
它是
/public_html/stats/*
。It's
/public_html/stats/*
.我实在是太懒了。我只是做了一个搜索,希望找到解决这个问题的捷径,但没有得到答案,所以我把它敲了出来。
~/bin/IGNORE_ALL
EG: IGNORE_ALL 添加了统计忽略
这只会将所有忽略文件附加到您的 .gitignore 并提交。请注意,您可能希望随后向文件添加注释。
I'm incredibly lazy. I just did a search hoping to find a shortcut to this problem but didn't get an answer so I knocked this up.
~/bin/IGNORE_ALL
EG: IGNORE_ALL added stat ignores
This will just append all the ignore files to your .gitignore and commit. note you might want to add annotations to the file afterwards.