2011-12-20 48 views

回答

2

如果您認爲將所有舊歷史導入Git是值得的,可以這樣做。但是,手動導入歷史記錄可能非常繁瑣,尤其是對於多個分支。有些人已經編寫腳本將現有VCS中的代碼導入到Git中,但顯然這不會直接適用於您的手動副本。

我會考慮你是否真的需要 Git中的所有歷史拷貝。如果沒有,那麼開始使用基本的Git操作和當前代碼,並從現在開始向前移動。

如果您仍想手動導入歷史,這裏是你如何能做到這一點以簡單的方式:

# create a new repository in the current directory 
git init 

# get snapshot #1 from files1 
cp ~/backup/files1/* . 
git add . 
git commit -m "files1 snapshot" 

# get shapshot #2 from files2 
cp ~/backup/files2/* . 
git add . 
git commit -m "files2 snapshot" 

# get snapshot in files_test into test_branch 
git checkout test_branch 
cp ~/backup/files_test/* . 
git add . 
git commit -m "files_test snapshot on branch test_branch" 

如果已經刪除修訂之間的文件,你還必須使用git rm以及git add完全記錄歷史。上面的高級使用可以讓您將提交日期和時間從當前時間更改爲您喜歡的任何時間戳。

+1

請注意,您可以使用'git add -A'來避免'git rm''ing – fge 2011-12-20 08:18:07

+1

確實如此,但在這種情況下,在複製下一個快照之前先清除工作目錄會很有用。 – 2011-12-20 08:20:51

相關問題