Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
671 views
in Technique[技术] by (71.8m points)

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. There are .gitattributes files scattered around the repo that specify the filter that should be used on the files at checkout. 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

I have created an alias 'reattr' to perform all those steps and now I am happy.

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""

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...