[英]git fast-import for existing files in the repository
我有本地 git 存儲庫和大量文件(約 400 萬,總大小約 700GB),我想檢查到 git。 使用 git 過濾器,我想跟蹤的不是文件的真實內容,而是對文件的一些引用(類似於git lfs
正在做的事情)。 添加和提交文件(分塊)仍然需要很長時間,我希望通過使用git fast-import
來減少時間。
不過,我不知道如何使用git fast-import
精確復制git add <file> && git commit -m <message>
。 讓我們考慮以下情況:
mkdir /tmp/git_fast_test && cd /tmp/git_fast_test
git init
echo "1234" > testfile
現在我運行以下 python 腳本,它將模式為 644 和內容為1234
的文件testfile
提交到 git 存儲庫。 這現在應該與/tmp/git_fast_test/testfile
完全對應。
import subprocess
import time
proc = subprocess.Popen(["git", "fast-import"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd="/tmp/git_fast_test")
proc.stdin.write(b"commit refs/heads/master\n")
proc.stdin.write(b"committer Me <me@me.org> %d +0100\n" % int(time.time()))
# commit message
proc.stdin.write(b"data 5\n")
proc.stdin.write(b"abcde\n")
# add file a with content `1234`
proc.stdin.write(b"M 644 inline testfile\n")
proc.stdin.write(b"data 4\n")
proc.stdin.write(b"1234\n")
proc.stdin.flush()
proc.stdin.close()
但是,在回購中我看到了這個:
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: testfile
Untracked files:
(use "git add <file>..." to include in what will be committed)
testfile
雖然 git 似乎知道 testfile:
$ git show testfile
commit 85f343fa205665e7304dfbad1725b640a0d03b01 (HEAD -> master)
Author: Me <me@me.org>
Date: Thu Jan 7 08:47:39 2021 +0100
abcde
diff --git a/testfile b/testfile
new file mode 100644
index 0000000..274c005
--- /dev/null
+++ b/testfile
@@ -0,0 +1 @@
+1234
\ No newline at end of file
那么,如何調整我的git fast-import
腳本以使 git 相信文件/tmp/git_fast_test/testfile
正是存儲在其索引中的內容?
我在原始 git 源代碼中找到了一個示例 shell 腳本,該腳本應該幾乎完全符合我的要求,並且與該腳本有相同的問題。 所以我相信這是git fast-import
的預期行為......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.