我之前被問及#git
的這個問題,但由於其合理實質性,我將在此處發佈它。我想在回購庫上運行filter-branch
,以使用python腳本通過數百次提交修改(數千個)文件。我在回購目錄使用以下命令調用clean.py
腳本:Git tree-filter在提交時運行python腳本
git filter-branch -f --tree-filter '(cd ../cleaner/ && python clean.py --path=files/*/*/**)'
Clean.py看起來是這樣的,並會修改所有文件路徑(即files/*/*/**
):
from os import environ as environment
import argparse, yaml
import logging
from cleaner import Cleaner
parser = argparse.ArgumentParser()
parser.add_argument("--path", help="path to run cleaner on", type=str)
args = parser.parse_args()
# logging.basicConfig(level=logging.DEBUG)
with open("config.yml") as sets:
config = yaml.load(sets)
path = args.path
if not path:
path = config["cleaner"]["general_pattern"]
cleaner = Cleaner(config["cleaner"])
print "Cleaning path: " + str(path)
cleaner.clean(path, True)
運行後將以下命令輸出到終端:
$ python deploy.py --verbose
INFO:root:Checked out master branch
INFO:root:Running command:
'git filter-branch -f --tree-filter '(cd C:/Users/Graeme/Documents/programming/clean-cdn/clean-jsdelivr/ && python clean.py --path=files/*/*/**)' -d "../tmp"' in ../jsdelivr
Rewrite 298ec3a2ca5877a25ebd40aeb815d7b5a5f33a7e (1/1535)
Cleaning path: files/*/*/**
C:\Program Files (x86)\git/libexec/git-core\git-filter-branch: line 343: ../commit: No such file or directory
C:\Program Files (x86)\git/libexec/git-core\git-filter-branch: line 346: ../map/298ec3a2ca5877a25ebd40aeb815d7b5a5f33a7e
: No such file or directory
could not write rewritten commit
rm: cannot remove `/c/Users/Graeme/Documents/programming/clean-cdn/tmp/revs': Permission denied
rm: cannot remove directory `/c/Users/Graeme/Documents/programming/clean-cdn/tmp': Directory not empty
python腳本成功執行並正確修改文件,但filter-branch
未完成修復提交。似乎有一個權限問題,但我還沒有能夠解決它與提升的特權運行。我試着在git v1.8和v1.9上運行win7,win8和ubuntu上的filter-branch。
編輯腳本可以作爲是Centros與git1.7.1
的目標是在files/*/*/**
完成了數據庫同步的內容後減少的CDN回購(接近1GB)的大小。
The source code of the project
Target repo for the rewrite
'git --version'的輸出是什麼? – michas
你能澄清你想要清潔的是什麼回購?它是https://github.com/jsdelivr/jsdelivr(當前包大小〜284MB)? –
@michas我試着在'v1.9.0','v1.8.5'和'1.8.3'上運行。是的,這是正確的回購羅伯託 – megawac