git .ignore 不在目录中工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6030530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git .ignore not working in a directory
提问by shin
I have the following .gitignore file
我有以下 .gitignore 文件
# file named .gitignore
system/application/config/database.php
system/application/config/config.php
system/logs
modules/recaptcha/config/*
However when I add any changes in config and recapcha.php, git status warns me as following. When I add any changes to database.php. it does not show it in status
但是,当我在 config 和 recapcha.php 中添加任何更改时,git status 会警告我如下。当我向database.php 添加任何更改时。它不会在状态中显示它
shin@shin-Latitude-E5420:/var/www/myapp$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: modules/recaptcha/config/recaptcha.php
# modified: system/application/config/config.php
#
no changes added to commit (use "git add" and/or "git commit -a")
How can I fix this?
我怎样才能解决这个问题?
Thanks in advance.
提前致谢。
I am using git version 1.7.5.1 on Ubuntu 11.04
我在 Ubuntu 11.04 上使用 git 版本 1.7.5.1
回答by DipSwitch
The files are already stored in your local commit tree. You'll need to first remove them from the repository. This can be done via:
这些文件已经存储在您的本地提交树中。您需要先从存储库中删除它们。这可以通过:
git rm --cached system/application/config/config.php modules/recaptcha/config/recaptcha.php
After that you'll need to make one more commit and you're good to go.
之后,您需要再进行一次提交,然后就可以开始了。
回答by Nanda Gopal
Do the following to trigger the gitignore
执行以下操作以触发gitignore
Step 1:Commit all your pending changes in the repo which you want to fix and push that.
第 1 步:在要修复的存储库中提交所有待处理的更改并推送它。
Step 2:Now you need to remove everything from the git index in order to refresh your git repository. This is safe. Use this command:
第 2 步:现在您需要从 git 索引中删除所有内容以刷新您的 git 存储库。这是安全的。使用这个命令:
git rm -r --cached .
Step 3:Now you need to add everything back into the repo, which can be done using this command:
第 3 步:现在您需要将所有内容添加回 repo,这可以使用以下命令完成:
git add .
Step 4:Finally you need to commit these changes, using this command:
第 4 步:最后,您需要使用以下命令提交这些更改:
git commit -m "Gitignore issue fixed"
回答by Eric Hogue
If your file is already in git before you add the directory to .gitignore git will keep tracking it. If you don't want it, do a "git rm" to remove it first.
如果您的文件在将目录添加到 .gitignore 之前已经在 git 中,则 git 将继续跟踪它。如果您不想要它,请先执行“git rm”以将其删除。
回答by sehe
I'm guessing yout .gitignore is not in the root of your working tree.
我猜你 .gitignore 不在你的工作树的根部。
If you put a .gitignore in the same directory as system/application/config/config.php you can just use
如果将 .gitignore 放在与 system/application/config/config.php 相同的目录中,则可以使用
echo config.php >> system/application/config/.gitignore
The paths are relative to the current directory (or: .gitignore is a per-directoryexclude/include file).
路径相对于当前目录(或:.gitignore 是每个目录的排除/包含文件)。
See man git-ignore
参见 man git-ignore