これはジャスティンの答えを拡張したものです。その後のリベース手順は複雑になる可能性があるため、含めませんでした。に相当しますがgit rebase -i newroot master
、マージ/追加/削除に関する微妙な点があります。たとえば、削除されたファイルをクリーンアップする必要がありました (ファイルを追加するだけなので、これらは取得されません)。
私のように、これらのレガシーインポートを現在のリポジトリのコミットの「前」にしたい場合は、次のようにする必要がありますgit checkout --orphan newroot
#!/usr/bin/python
import os
import sys
import datetime as dt
LEGACY_PATH = '/path/to/legacy'
REPO_PATH = '/path/to/repo'
AUTHOR_NAME = 'Your Author <your@author.com>'
def main():
os.chdir(REPO_PATH)
#We assume you are on the branch where you want to import
#Otherwise the following line will do
#os.system('git checkout --orphan newroot')
subdirs = sorted(os.listdir(LEGACY_PATH))
print subdirs
for d in subdirs:
fullpath = os.path.join(LEGACY_PATH, d)
legacy_date = dt.datetime.strptime(d, '%Y%m%d').isoformat()
cmd = 'git --git-dir=%s/.git --work-tree=%s add .' \
% (REPO_PATH, fullpath)
print '\n', cmd
os.system(cmd)
os.chdir(REPO_PATH)
cmd = 'git commit -m "Import changes from legacy version %s" \
--date=%s \
--author="%s"' \
% (d, legacy_date, AUTHOR_NAME)
print '\n', cmd
os.system(cmd)
if __name__ == "__main__":
main()