简体   繁体   English

git:创建涂抹过滤器后重新签出文件

[英]git: re-checkout files after creating smudge filter

Situation: I've just cloned a git repo, and then I configure the smudge filter for the repo. 情况:我刚刚克隆了一个git repo,然后我为repo配置了涂抹过滤器。 There are .gitattributes files scattered around the repo that specify the filter that should be used on the files at checkout. 在repo周围散布着.gitattributes文件,指定在结帐时应该在文件上使用的过滤器。 But since I setup the filter after the checkout (clone), none of the files were processed. 但是因为我在结帐(克隆)之后设置了过滤器,所以没有处理任何文件。

How can I tell git to go through the repo, find all the .gitattributes files, and update (re-checkout, apply filter, whatever) all the files which have a smudge filter on them? 我如何告诉git通过repo,找到所有.gitattributes文件,并更新(重新检出,应用过滤器,等等)所有带有污迹过滤器的文件?

Simply re-checkout everything. 只需重新检查一切。

cd /path/to/your/repo
git stash save
rm .git/index
git checkout HEAD -- "$(git rev-parse --show-toplevel)"
git stash pop

The smudge filter will be applied at that new checkout. 涂抹过滤器将应用于新的结帐。

Note, as seen in this answer , you need to remove the index in order to force the filter to run again. 请注意,如本答案中所示 ,您需要删除索引才能强制过滤器再次运行。

Alexander Amelkin comments below : Alexander Amelkin评论如下

I have created an alias ' reattr ' to perform all those steps and now I am happy. 我创建了一个别名' reattr '来执行所有这些步骤,现在我很高兴。

reattr = !sh -c "\"git stash save; rm .git/index; git checkout HEAD -- \\\"$(git rev-parse --show-toplevel)\\\"; git stash pop\""

(multi-line for readability) (多行可读性)

reattr = !sh -c "\"git stash save; \
                   rm .git/index; \
                   git checkout HEAD -- \\\"$(git rev-parse --show-toplevel)\\\"; \
                   git stash pop\""

You can remove the Git index and let Git rescan it to aware the changes. 您可以删除Git索引并让Git重新扫描它以了解更改。 Then you can checkout all the files which have a smudge filter on them. 然后你可以检查所有带有污迹过滤器的文件。

# remove Git index
rm .git/index

# rescan index
git reset HEAD -- .

# checkout all the files which have a smudge filter on them
git ls-files --modified | grep -v .gitattributes | awk '{print "git checkout HEAD -- \""$1"\""}' | bash

Note: Save your uncommitted changes before the re-checkout, otherwise, all your modifications on those smudge-filter-applied files will be overridden. 注意:在重新签出之前保存未提交的更改,否则,将覆盖对这些涂抹滤镜应用的文件的所有修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM