如何忽略 Git 中的现有文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20525055/
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
How to ignore existing file in Git?
提问by kassie
I need to work on file.txt
locally and in Git, with different content. I want Git not to tell me that there have been changes to that file.
我需要在file.txt
本地和 Git 中使用不同的内容。我希望 Git 不要告诉我该文件已更改。
Is this possible?
这可能吗?
回答by Tom Auger
Actually, you want --skip-worktree
, not --assume-unchanged
. Here's a good explanation why.
实际上,您想要--skip-worktree
,而不是--assume-unchanged
。这是一个很好的解释为什么。
So git update-index --skip-worktree file.txt
所以 git update-index --skip-worktree file.txt
TLDR; --assume-unchanged
is for performance, for files that won't change (like SDKs); --skip-worktree
is for files that exist on remote but that you want to make local (untracked) changes to.
TLDR;--assume-unchanged
用于性能,用于不会更改的文件(如 SDK);--skip-worktree
用于远程存在但您想要对其进行本地(未跟踪)更改的文件。
回答by janos
Maybe you want to "pretend" that the file hasn't changed when actually it did? You can do that like this:
也许您想“假装”文件实际上没有改变?你可以这样做:
git update-index --assume-unchanged file.txt
To undo this later:
要稍后撤消此操作:
git update-index --no-assume-unchanged file.txt
To view a list of files that are marked this way:
要查看以这种方式标记的文件列表:
git ls-files -v | grep '^[a-z]'
UPDATE
更新
As comments have pointed out, this is most probably NOT what you want to do. A better answerhas been posted by @Tom Auger, use that instead.
正如评论指出的那样,这很可能不是您想要做的。@Tom Auger发布了一个更好的答案,请改用它。
回答by hillu
If modifying the .gitignore
file is not an option (because it is checked into git itself), consider using .git/info/exclude
.
如果修改.gitignore
文件不是一个选项(因为它已检入 git 本身),请考虑使用.git/info/exclude
.
回答by antonio
All you need is to click the more
button in sourcetree just at the right hand side of the filename, in the unstaged files section. Click ignore
and make source tree perform your desired action for that file or all the files with the same type.
您只需要more
在未暂存文件部分中单击文件名右侧的源树中的按钮。单击ignore
并使源代码树对该文件或具有相同类型的所有文件执行所需的操作。
回答by Limitless isa
SOURCETREE Terminal codes
SOURCETREE 终端代码
Add ignore file:
添加忽略文件:
git update-index --skip-worktree index.php
Extract ignore file:
提取忽略文件:
git update-index --no-skip-worktree index.php
List ignore files:
列出忽略文件:
git ls-files . --ignored --exclude-standard --others
回答by abasterfield
Can you not use .gitignorefile?
你不能使用.gitignore文件吗?
回答by cellepo
In Eclipse Luna, this can be done [with EGit plugin I think] by doing this: right-click file -> Team -> Advanced -> Assume unchanged
在 Eclipse Luna 中,这可以通过以下方式完成 [我认为使用 EGit 插件]:右键单击文件 -> 团队 -> 高级 -> 假设不变