æ¦è¦
- Git ã®ãã£ã«ã¿ã¼ã«ã¯ä¸»ã« 2 㤠clean ãã£ã«ã¿ã¼ã¨ smudge ãã£ã«ã¿ã¼ããã
git add
ã³ãã³ããå®è¡ããéã« clean ãã£ã«ã¿ã¼ãå®è¡ããããã®æ¨æºåºåã¸ã git ãªãã¸ã§ã¯ãã«ãªãgit clone
ãå®è¡ããéã« git ãªãã¸ã§ã¯ãã« smudge ãã£ã«ã¿ã¼ãå®è¡ããããã®æ¨æºåºåããã¼ã«ã«ã®ãã¡ã¤ã«ã«ãªã- ãã£ã«ã¿ã¼ã®é©ç¨æç¡ã¯
.gitattributes
ãã¡ã¤ã«ã«ã¦æå®ããããã£ã«ã¿ã¼ã®å 容ã¯.git/config
ã§æå®ããã
åæ©
æ®æ®µã®ä»äºã§ Git LFS ãæ±ã£ãéã«ããã¤ã³ã¿ã¼ãã¡ã¤ã«ã¨ãã¤ããªã¼ãã¡ã¤ã«ãç¸äºã«ç½®ãæããä»çµã¿ãããããªãã£ãã®ã§èª¿ã¹ãã
Git LFS
Git LFS ã使ãããã«è¨å®ããã¨ã .gitattributes
ãã¡ã¤ã«ã .git/config
ãã¡ã¤ã«ã«ä»¥ä¸ã®ããã¹ãã追å ããã
ã³ãã³ã
git lfs install git lfs track '*.png'
.gitattributes
ãã¡ã¤ã«
*.png filter=lfs diff=lfs merge=lfs -text
.git/config
ãã¡ã¤ã«ã¨ gitconfig --list
ã³ãã³ãã®çµæ
.git/config
ãã¡ã¤ã«
[filter "lfs"] clean = git-lfs clean -- %f smudge = git-lfs smudge -- %f
gitconfig --list
ã³ãã³ãã®çµæ
filter.lfs.clean=git-lfs clean -- %f filter.lfs.smudge=git-lfs smudge -- %f
.gitattributes
ãã¡ã¤ã«ãè¦ãã¨ã*.png
ãã¡ã¤ã«ã¯ãã¹ã¦ããã¹ãã¨ãã¦ã¯æ±ãã(-text
) diff ããå ´åã¯git-lfs-diff
ã使ãããã¼ã¸ã®ã¨ãã¯â¦åâ¦ãfilter
ã¯lfs
ãã£ã«ã¿ã¼ã使ãã¨ããã®ããããã- å½ã®
lfs
ãã£ã«ã¿ã¼([filter "lfs"]
)ã§ã¯ãclean
ã¨smudge
ãã£ã«ã¿ã¼ãç¨æããã¦ãã¦ãããããgit-lfs-clean
git-lfs-smudge
ãæå®ããã¦ããã®ã§ãããããããããã¤ã³ã¿ã¼ãã¡ã¤ã«ã¨å®éã®ãªãã¸ã§ã¯ãã交æããã³ãã³ãã§ããã¨ãããã
Git ã®ãã£ã«ã¿ã¼
Git ã®ãã£ã«ã¿ã¼ã«ã¤ãã¦ã¯ãå ¬å¼ã®ããã¥ã¡ã³ãã詳ããã
ãã£ããè¨ãã°ã 次ã®éãã
- staging(è¦ããã«
git add
ãã¦ç®¡çç¶æ ã«ãããã¨) ã«ãããã¡ã¤ã«ã«ããã¨ã ãã¼ã«ã«ã®ãã¡ã¤ã«åã clean ãã£ã«ã¿ã¼ã«æ¸¡ããã¦ããã®æ¨æºåºåã®å 容ã staging ã¨ãã¦ç®¡çãããã - clone ãªã©ã§åå¾ããå ´åã¯ã staging ã®ãªãã¸ã§ã¯ãã smudge ãã£ã«ã¿ã¼ã«æ¸¡ããã¦ããã®æ¨æºåºåã®å 容ã ãã¼ã«ã«ã®ãã¡ã¤ã«ã¨ãã¦ä¿åãããã
ããããã¨ãgit-lfs
ã§ãªãã¦ããèªä½ã®ã³ãã³ãã§åä½ã確ãããããã®ã§ã¯ãªããã¨èããããã
å®é¨
ä¼ç»
- clean ãã£ã«ã¿ã¼ã«å¯éãªå¤æ´ãå ããã³ãã³ããè¨å®ããã
- smudge ãã£ã«ã¿ã¼ãåæ§ã« clean ãã£ã«ã¿ã¼ã®å¤æ´ããã¨ã«æ»ãã³ãã³ããè¨å®ããã
- ããã¹ããã¡ã¤ã«ãä¸è¨ã®ãã£ã«ã¿ã¼ã«éããã®ã¨ããã
- ä¸è¨ã®è¨å®ã®ãã¨ã¬ãã¸ããªã¼ãä½æã» GitHub ã« push ããä¸ã§ã clone ãã¦ããã¼ã«ã«ã»å¥ãã±ã¼ã·ã§ã³ããããã®ãã¡ã¤ã«ã®ç¶æ
ã観å¯ãã
- ããã¹ããã¡ã¤ã«ãä½æãã git 管çã«(
git add
)ããã¨ãã« clean ãã£ã«ã¿ã¼ãé©ç¨ããã¦ãããã¨ã確èªãã - ãªã¢ã¼ããã clone ãã¦ããã¨ãã«ã smudge ãã£ã«ã¿ã¼ãé©ç¨ããã¦å ã®ãã¡ã¤ã«ã«ãªã£ã¦ãããã¨ã確èªãã
- ããã¹ããã¡ã¤ã«ãä½æãã git 管çã«(
æºå
.gitattributes
ãã¡ã¤ã«.git/config
ãã¡ã¤ã«
ããã§ã¯ã
- ããã¹ããã¡ã¤ã«ã«è¡çªå·ãä»ä¸ãã clean ãã£ã«ã¿ã¼
- è¡çªå·ã®ä»ä¸ãããããã¹ããã¡ã¤ã«ããè¡çªå·ãåãé¤ã smudge ãã£ã«ã¿ã¼
ãæºåããã
1..gitattributes
ãã¡ã¤ã«
*.txt filter=example text eol=lf
2..git/config
ãã¡ã¤ã«
%f
ã«ã¯ãã¡ã¤ã«ã®ãã¹ã渡ããã¾ãã- ãã¡ã¤ã«ã®å 容ã¯æ¨æºå ¥åã«æ¸¡ãããããã§ãã
- æ¨æºåºåã¸ã®åºåå 容ããã¡ã¤ã«ã®ã³ã³ãã³ãã«ãªãããã§ãã
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [filter "example"] clean = cat -n %f smudge = sed 's|^[[:space:]]*[1-9][0-9]*[[:space:]]||g'
å®é¨1 clean ãã£ã«ã¿ã¼
ã¾ãé©å½ãªãã¡ã¤ã«ãä½æãã¦ãgit 管ç対象ã«ããã
for item in {foo,bar,baz}; do echo "item = ${item}" if [[ "${item}" =~ ^ba ]]; then echo "" fi done | tee text.txt git add text.txt
ãã¡ã¤ã«ã®ä¸ã確èªããã
cat text.txt
ç¶ãã¦ã hash å¤ããå 容ã確èªãããã¹ãã¼ã¸ããããã¡ã¤ã«ã¯ è¡çªå·ãä»ä¸ããã¦ããã¯ãã§ããã
git ls-files --stage text.txt git cat-file [ä¸è¨ã®ã³ãã³ãã®çµæ]
è¡çªå·ãä»ä¸ããã¦ãããã¨ãããã
å®é¨2 smudge ãã£ã«ã¿ã¼
å®é¨1ã®ãã¨ã«ã³ããããã
git commit -m 'add text'
ãã®å¾ã«ããã¡ã¤ã«ãæ¶ãã¦ãããªã¹ãã¢ãã¦ã¿ãã
rm text.txt git status git restore text.txt
ãã¡ã¤ã«ã復å ããã¦ãããã¨ããããã
å®é¨3 clone
ãã®ã¬ãã¸ããªã¼ã GitHub ã« push ãã¦ãããå¥ã®ãã£ã¬ã¯ããªã¼ã§ clone ãã¦ã¿ãã
äºåã«èª¿ã¹ãçµæã§ã¯ã clone ãã¦ããå¾ã®ã¬ãã¸ããªã¼ã§ã¯ smudge ãã£ã«ã¿ã¼ã®ããã£ãã³ã³ãã³ãã§ãªãã¦ã clean ãã£ã«ã¿ã¼ã®ããã£ãç¶æ
ã«ãªã£ã¦ãããã¨ãããã£ã¦ãããããã¯ã clean / smudge ãã£ã«ã¿ã¼ã¨ãã« .git/config
ã®ä¸ã§å®ç¾©ããã¦ãããã clone ã¯ãã®è¨å®ããã¦ã³ãã¼ãã§ããªãããã§ãã(push ããããã¦ããªãã¯ãâ¦)ã
ãã®ãããããã§ã¯ clone ããå ´åã®ãã¡ã¤ã«ã®ç¶æ ã確èªãã¦ã¿ãã
ã¾ã GitHub ã«ããã·ã¥ããã
git remote add github https://github.com/mike-neck/my-git-filter-example.git git push github main
ãªãã push ããããã®ã¯è¡çªå·ãä»ä¸ãããç¶æ ã«ãªã£ã¦ããã
å¥ã®ãã£ã¬ã¯ããªã¼ã«ç§»åã㦠clone ãã¦ããã¡ã¤ã«ã確èªãã¦ã¿ãã
git clone https://github.com/mike-neck/my-git-filter-example.git cd my-git-filter-example bat text.txt
è¦äº(?)ã« smudge ãã£ã«ã¿ã¼ã®ããããªãç¶æ ã«ãªã£ã¦ããã
ãã㧠.git/config
ãè¦ã¦ã¿ãã¨ããã£ã«ã¿ã¼ã®è¨å®ã¯åå¨ããªã(ããã¯ãã)ã®ã§å
ã®ç¶æ
(è¡çªå·ã®ãªãç¶æ
)ã«æ»ããªãã
bat .git/config
å®é¨4 åããã£ã«ã¿ã¼ãå°å ¥
次ã«åããã£ã«ã¿ã¼ã clone ãã¦ããæ¹ã®ã¬ãã¸ããªã¼ã«å°å ¥ãã¦ã¿ãã ãã¡ã¤ã«ã®æ¯è¼ã¯ merge ãã£ã«ã¿ã¼ãæå®ãã¦ãªãã®ã§ã clean ãã£ã«ã¿ã¼é©ç¨ãããã®(è¡çªå·ã¤ããã¡ã¤ã« vs è¡çªå·ä»ãè¡çªå·ã¤ããã¡ã¤ã«)ã«ãªãã¨äºæ³ã
grep -A2 'filter "example"' path/to/original-path/.git/config grep -A2 'filter "example"' path/to/original-path/.git/config >> .git/config git status
git status
ã®çµæã¯æå¤ã«ãå¤æ´ãªãã ã£ã
ãã®ç¶æ
ã§ã¯ãªã¢ã¼ãã¨ãã¼ã«ã«ã§åããã¡ã¤ã«ã®ç·¨éãã§ããªãã®ã§ãgit cat-file
ã³ãã³ãã§å¾©å
ãããã
git cat-file --filters HEAD:text.txt
git cat-file --filters HEAD:text.txt > text.txt
git status
git diff text.txt
git add text.txt
git status
ããã§ã git status
ã§å¤æ´ãçºçãã¦ããããã«è¡¨ç¤ºãããããå
ã®ãã¡ã¤ã«ã¨åããªã®ã§ git diff
ã§å·®ç°ã¯ç¢ºèªã§ããªãã
ããã« git add
ããã¨ã git status
ã¯å¤æ´ãªãã«æ»ã£ããããã§ãã£ã«ã¿ã¼ã®ããããã¸ã§ã¯ãã®é©åãªç¶æ
ã«ãªã£ãã¨è¨ãããããã£ã«ã¿ã¼ãè¨å®ããã¦ãããªãã¸ããªã¼ã® clone ã¯ãããã®æä½æ¥ããã£ã¦ãããã½ããã¦ã§ã¢ãå¿
è¦ã§ãããã¨ããããã
å®é¨5 fetch + pull
å ã®ãã¼ã«ã«ã¬ãã¸ããªã¼ã«ã¦æ°ãã«ãã¡ã¤ã«ãä½æã»ããã·ã¥ããå¾ã«ãã¯ãã¼ã³ãããã¼ã«ã«ã¬ãã¸ããªã¼ã§ pull ããå ´åã«ã smudge ãã£ã«ã¿ã¼ãé©ç¨ããã¦ããã®ã確èªããã
cd path/to/original-path for item in {foo,bar,baz}; do echo "${item}"; done > another.txt git add another.txt git commit -m 'add another text' git push origin "$(git rev-parse --abbrev-ref HEAD)" cd pth/to/my-git-filter-example git pull origin git status
å ã®ã¬ãã¸ããªã¼
ã¯ãã¼ã³ããã¬ãã¸ããªã¼ã§ git pull
ãã¡ã¤ã«ã®ä¸èº«ã確èªâè¡çªå·ã¯ãªãâsmudgeãã£ã«ã¿ã¼ãå®è¡ããã¦ãã
ãã¡ãã GitHub ã§ã¯ è¡çªå·ä»ãã®ãã¡ã¤ã«ã«ãªã£ã¦ããã(GitHub ã§ã¯smudgeãã£ã«ã¿ã¼ãé©ç¨ããã¦ããªã)
clean ãã£ã«ã¿ã¼ã¨ smudge ãã£ã«ã¿ã¼ã®ä»çµã¿ãå³ç¤ºããã¨ä»¥ä¸ã®å³ã®ããã«ãªãã
ã¾ã¨ã
- Git ã®ãã£ã«ã¿ã¼ã«ã¯ clean ãã£ã«ã¿ã¼ã¨ smudge ãã£ã«ã¿ã¼ããã
- clean ãã£ã«ã¿ã¼ã¯
git add
ãã㦠Git ã®ãªãã¸ã§ã¯ãã«ç»é²ãããã¨ãã«é©ç¨ããã - smudge ãã£ã«ã¿ã¼ã¯ git blob ãªãã¸ã§ã¯ããã復å ããå¾ã«é©ç¨ããã
- clean ãã£ã«ã¿ã¼ã¯
- Git ã®ãã£ã«ã¿ã¼ã¯
.gitattributes
ã¨.git/config
ã®çµã¿åããã§æå®ãã- ãªã¢ã¼ããã clone ããå ´åã«ã
.git/config
ã¯åæãããªãã®ã§ãå¥éæºåããå¿ è¦ããã - clone ãã¦ããå¾ã®ãã¡ã¤ã«ã« sumudge ãã£ã«ã¿ã¼ã¯é©ç¨ããã¦ããªãã®ã§ãå¥éé©ç¨ããå¿ è¦ããã
- ãªã¢ã¼ããã clone ããå ´åã«ã
- Git LFS ã¯ä¸è¨ã®ä»çµã¿ãèªåã§é©ç¨ããã½ããã¦ã§ã¢ã§ãã
- ã¬ãã¸ããªã¼ã clone ããå ´åãé常ã®
git clone
ã®ä»£ããã«git lfs clone
ã使ã
- ã¬ãã¸ããªã¼ã clone ããå ´åãé常ã®