如何强制 git 将点文件添加到存储库

发布于 2024-08-23 10:30:13 字数 213 浏览 3 评论 0原文

Git 似乎总是忽略这些。

当我输入 git add . 时,会添加 GIT_DIR 中的点文件,但不会添加子目录中的点文件。另一方面, git add subdir/.dotfile 不起作用。

我尝试了 git add -f 并将 !.* 放入 GIT_DIR/.git/info/exclude 中。

Git seems to always ignore these.

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.

I tried git add -f and putting !.* in GIT_DIR/.git/info/exclude.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

挖个坑埋了你 2024-08-30 10:30:13

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

您使用什么版本的 Git?您的子目录实际上是子模块(独立管理)吗?

默认情况下不排除“点文件”,但也许您的系统、存储库或工作树上的某些配置已将它们设置为这种方式。如果它们出现在 git ls-files --exclude-standard -oi 中,那么它们将被忽略,“!.*”是“取消忽略”它们的正确方法。但为了有效,这种模式必须处于正确的位置。忽略按以下顺序处理:

  • 直接包含目录的 .gitignore,然后是
  • 父目录的 .gitignore(每个父目录,直到存储库根目录),然后
  • >$GIT_DIR/info/exclude,然后
  • git config core.excludesfile 报告的文件(可以通过以下方式设置)
    • $GIT_DIR/config
    • $HOME/.gitconfig,或
    • 系统配置文件(尝试 GIT_EDITOR=echo git config --system --edit 获取其路径名)。

当路径名与一个文件中的模式匹配时,不会查阅后续文件。每个文件中的最后一场比赛“获胜”。 $GIT_DIR/info/exclude 中的模式永远不能覆盖 .gitignore 文件中的模式。因此,如果文件被忽略(根据 git ls-files --exclude-standard -oi )并且如果 $GIT_DIR/info/exclude 中存在“!.*”无效,然后检查所有适用的 .gitignore 文件以查找罪魁祸首。

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 --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)?

“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:

  • .gitignore of the immediately containing directory, then
  • .gitignore of 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)).

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/exclude can never override a pattern in a .gitignore file. So, if the files are being ignored (per git ls-files --exclude-standard -oi) and if "!.*" in $GIT_DIR/info/exclude is ineffective, then check all the applicable .gitignore files for the culprit.

趴在窗边数星星i 2024-08-30 10:30:13

您可以通过路径名专门添加它们,例如,

git add */.*

或者

find . -name '.[a-z]*' -exec git add '{}' ';'

(最好小心 -name,因为您不一定希望使用其 来选取每个目录。条目。)

但到目前为止,最简单的方法是使用git gui。只需单击文件即可。

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.)

But by far the easiest way to do this is with git gui. Just click on the files.

亽野灬性zι浪 2024-08-30 10:30:13

如果您只需要添加几个 .dotfiles,我建议使用 -f 标志,因为简单的 git add .yourDotFilegit 版本 2.28.8 上不起作用 并且您不想弄乱全局 .gitignore。因此使用 git add .yourDotFile -f

If there are only few .dotfiles you need to add, I recommend using -f flag since simple git add .yourDotFile does not work on git version 2.28.8 and you do not want to mess with global .gitignore. Therefore use git add .yourDotFile -f

奢华的一滴泪 2024-08-30 10:30:13

我只是强迫它:

git add . -f

干杯。

I just forced it with:

git add . -f

Cheers.

じ违心 2024-08-30 10:30:13

我使用

find . -type f | grep -vP '^.\/.git' |  xargs git add

grep -vP '^.\/.git' 排除以 .git 开头的所有内容,并查找获取所有文件,包括所有隐藏文件。

i use

find . -type f | grep -vP '^.\/.git' |  xargs git add

the grep -vP '^.\/.git' exclude everthing wich start with .git and find get all files include all hidden files.

欲拥i 2024-08-30 10:30:13

我不喜欢使用“查找”的想法,因为它可能会找到你告诉 git 忽略的东西。您可以使用 bash 脚本。该脚本只会“添加”已修改的文件,而不是未跟踪的文件:

#!/bin/bash
addFile=false

theseLines=($(git status))
for thisLine in "${theseLines[@]}" ; do

  if [[ "${addFile}" == 'true' ]] ; then
    git add $thisLine
    addFile=false
  fi
  if [[ "${thisLine}" == 'modified:' ]] ; then
    addFile=true
    #echo 'the next line will be a file that should be added'
  fi

done

I dont like the idea of using a 'find' as it might find things you told git to ignore. You could use a bash script. This script will only 'add' a file that is modified, not untracked:

#!/bin/bash
addFile=false

theseLines=($(git status))
for thisLine in "${theseLines[@]}" ; do

  if [[ "${addFile}" == 'true' ]] ; then
    git add $thisLine
    addFile=false
  fi
  if [[ "${thisLine}" == 'modified:' ]] ; then
    addFile=true
    #echo 'the next line will be a file that should be added'
  fi

done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文