强制 git 将 dotfiles 添加到存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2352455/
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
Force git to add dotfiles to repository
提问by Sergey Kovalev
How can I add files starting with dot (hidden files) in git repo? Git seems to always ignore those.
如何在 git repo 中添加以点开头的文件(隐藏文件)?Git似乎总是忽略这些。
When I type git add .
, dotfiles in GIT_DIR
are added, but not from subdirectories. On the other hand, git add subdir/.dotfile
won't work.
当我输入时git add .
,GIT_DIR
会添加点文件,但不会从子目录中添加。另一方面,git add subdir/.dotfile
行不通。
I tried git add -f
and putting !.*
in GIT_DIR/.git/info/exclude
. No luck.
我想git add -f
,并把!.*
在GIT_DIR/.git/info/exclude
。没运气。
回答by Chris Johnsen
git add .
and git add dir/.dot
work fine for me with the unadorned 1.6.6.1 and 1.7.0 versions of Git that I have handy right now.
git add .
并且git add dir/.dot
使用我现在手头的未修饰的 1.6.6.1 和 1.7.0 版本的 Git 对我来说很好用。
% git --version
git version 1.6.6.1
% git ls-files -o
.baz/baz
.foo
bar/.bar
quuux/quuux
quux
% git add .
% git ls-files -o
% git ls-files
.baz/baz
.foo
bar/.bar
quuux/quuux
quux
What version of Git are you using? Are your subdirs actually submodules (which are managed independently)?
你使用的是哪个版本的 Git?您的子目录实际上是子模块(独立管理)吗?
“dot files”?are not excluded by default, but maybe some bit of configuration on your system, repository, or working tree has them set that way. If they show up in git ls-files --exclude-standard -oi
then they are being ignored and "!.*" is the right way to ‘unignore' them. But to be effective, that pattern has to be in the right place. Ignores are processed in this order:
“点文件”?默认情况下不排除,但也许您的系统、存储库或工作树上的一些配置将它们设置为这种方式。如果它们出现,git ls-files --exclude-standard -oi
那么它们将被忽略,“!.*”是“忽略”它们的正确方法。但要有效,这种模式必须在正确的位置。忽略按以下顺序处理:
- .gitignoreof the immediately containing directory, then
- .gitignoreof the parent directory (each parent, up to the repository root), then
- $GIT_DIR/info/exclude, then
- the file reported by
git config core.excludesfile
(which could be set by- $GIT_DIR/config,
- $HOME/.gitconfig, or
- the system config file (try
GIT_EDITOR=echo git config --system --edit
to get its pathname)).
- .gitignore直接包含的目录,然后
- .gitignore父目录(每个父目录,直到存储库根目录),然后
- $GIT_DIR/info/exclude,然后
- 报告的文件
git config core.excludesfile
(可以由- $GIT_DIR/config,
- $HOME/.gitconfig,或
- 系统配置文件(尝试
GIT_EDITOR=echo git config --system --edit
获取其路径名))。
When a pathname matches a pattern in one file, subsequent files are not consulted. The last match in each file “wins”. A pattern in $GIT_DIR/info/excludecan never override a pattern in a .gitignorefile. So, if the files are being ignored (per git ls-files --exclude-standard -oi
) and if "!.*" in $GIT_DIR/info/excludeis ineffective, then check all the applicable .gitignore
files for the culprit.
当路径名与一个文件中的模式匹配时,不会查询后续文件。每个文件中的最后一场比赛“获胜”。在模式$ GIT_DIR /信息/排除不能覆盖在图案的.gitignore文件。因此,如果文件被忽略(per git ls-files --exclude-standard -oi
)并且$GIT_DIR/info/exclude 中的“!.*”无效,则检查所有适用.gitignore
文件以查找罪魁祸首。
回答by Norman Ramsey
You can add them specifically by pathname, e.g.,
您可以通过路径名专门添加它们,例如,
git add */.*
or
或者
find . -name '.[a-z]*' -exec git add '{}' ';'
(It's good to be careful with the -name
because you don't necessarily want to pick up every directory with its .
entry.)
(小心使用 是很好的,-name
因为您不一定要选择每个目录及其.
条目。)
But by far the easiest way to do this is with git gui
. Just click on the files.
但到目前为止,最简单的方法是使用git gui
. 只需单击文件。
回答by Angel O'Sphere
Interestingly under windows 10 with git version 2.12.0.windows.1 running under "Git-Bash" an "git add .*" fails, too. Files like .classpath and .project etc. are not added and hence later not commited. But well, this is the wrong palce to file a bug report.
有趣的是,在 git 版本 2.12.0.windows.1 在“Git-Bash”下运行的 Windows 10 下,“git add .*”也失败了。像 .classpath 和 .project 等文件没有被添加,因此以后也不会被提交。但是,这是提交错误报告的错误位置。
回答by GS_ZS GS_ZS
Restrictions on hidden files starting with .can be removed in the global .gitignore
可以在全局 .gitignore 中删除对以 . 开头的隐藏文件的限制