-
A1. 附錄 A: Git 在其他環境
- A1.1 圖形介面
- A1.2 Visual Studio 中的 Git
- A1.3 Visual Studio Code 中的 Git
- A1.4 IntelliJ / PyCharm / WebStorm / PhpStorm / RubyMine 中的 Git
- A1.5 Sublime Text 中的 Git
- A1.6 Bash 中的 Git
- A1.7 Zsh 中的 Git
- A1.8 PowerShell 中的 Git
- A1.9 小結
-
A2. 附錄 B: 在應用程式中嵌入 Git
-
A3. 附錄 C: Git 命令
9.2 Git 與其他系統 - 遷移到 Git
遷移到 Git
如果您在另一個 VCS 中擁有現有程式碼庫,但已決定開始使用 Git,則必須以某種方式遷移您的專案。本節將介紹一些常見系統的匯入器,然後演示如何開發您自己的自定義匯入器。您將學習如何從一些主要的專業 SCM 系統匯入資料,因為它們構成了大多數正在切換的使用者,而且它們的優質工具也易於獲取。
Subversion
如果您閱讀了前面關於使用 git svn
的章節,您可以輕鬆地使用這些說明來 git svn clone
一個倉庫;然後,停止使用 Subversion 伺服器,推送到新的 Git 伺服器,並開始使用它。如果您想要歷史記錄,您可以像從 Subversion 伺服器拉取資料一樣快速地完成(這可能需要一段時間)。
然而,匯入並不完美;而且由於需要很長時間,您最好把它做好。第一個問題是作者資訊。在 Subversion 中,每個提交者在系統上都有一個使用者,該使用者記錄在提交資訊中。前面章節中的示例在某些地方顯示 schacon
,例如 blame
輸出和 git svn log
。如果您想將其對映到更好的 Git 作者資料,您需要一個從 Subversion 使用者到 Git 作者的對映。建立一個名為 users.txt
的檔案,其中包含如下格式的對映:
schacon = Scott Chacon <schacon@geemail.com>
selse = Someo Nelse <selse@geemail.com>
要獲取 SVN 使用的作者姓名列表,您可以執行此命令:
$ svn log --xml --quiet | grep author | sort -u | \
perl -pe 's/.*>(.*?)<.*/$1 = /'
這會生成 XML 格式的日誌輸出,然後只保留包含作者資訊的行,去除重複項,並剝離 XML 標籤。顯然,這隻適用於安裝了 grep
、sort
和 perl
的機器。然後,將該輸出重定向到您的 users.txt
檔案,這樣您就可以在每個條目旁邊新增等效的 Git 使用者資料。
注意
|
如果您在 Windows 機器上嘗試此操作,則會遇到麻煩。Microsoft 在 https://learn.microsoft.com/en-us/azure/devops/repos/git/perform-migration-from-svn-to-git 提供了很好的建議和示例。 |
您可以將此檔案提供給 git svn
以幫助它更準確地對映作者資料。您還可以透過向 clone
或 init
命令傳遞 --no-metadata
來告訴 git svn
不包含 Subversion 通常匯入的元資料。元資料在 Git 匯入期間生成的每個提交訊息中包含一個 git-svn-id
。這可能會使您的 Git 日誌變得龐大,並可能使其有點不清晰。
注意
|
當您想將 Git 倉庫中進行的提交映象回原始 SVN 倉庫時,您需要保留元資料。如果您不想在提交日誌中進行同步,請隨意省略 |
這將使您的 import
命令看起來像這樣:
$ git svn clone http://my-project.googlecode.com/svn/ \
--authors-file=users.txt --no-metadata --prefix "" -s my_project
$ cd my_project
現在,您應該在 my_project
目錄中有一個更好的 Subversion 匯入。提交不再看起來像這樣:
commit 37efa680e8473b615de980fa935944215428a35a
Author: schacon <schacon@4c93b258-373f-11de-be05-5f7a86268029>
Date: Sun May 3 00:12:22 2009 +0000
fixed install - go to trunk
git-svn-id: https://my-project.googlecode.com/svn/trunk@94 4c93b258-373f-11de-
be05-5f7a86268029
它們看起來像這樣:
commit 03a8785f44c8ea5cdb0e8834b7c8e6c469be2ff2
Author: Scott Chacon <schacon@geemail.com>
Date: Sun May 3 00:12:22 2009 +0000
fixed install - go to trunk
不僅作者欄位看起來好多了,而且 git-svn-id
也不再存在。
您還應該做一些匯入後的清理工作。首先,您應該清理 git svn
設定的那些奇怪的引用。您將把標籤移動成實際的標籤而不是奇怪的遠端分支,然後將其餘分支移動到本地。
要將標籤移動為正確的 Git 標籤,請執行:
$ for t in $(git for-each-ref --format='%(refname:short)' refs/remotes/tags); do git tag ${t/tags\//} $t && git branch -D -r $t; done
這會將以 refs/remotes/tags/
開頭的遠端分支引用轉換為真實的(輕量級)標籤。
接下來,將 refs/remotes
下的其餘引用移動為本地分支:
$ for b in $(git for-each-ref --format='%(refname:short)' refs/remotes); do git branch $b refs/remotes/$b && git branch -D -r $b; done
您可能會看到一些以 @xxx
(其中 xxx 是一個數字)為字尾的額外分支,而在 Subversion 中您只看到一個分支。這實際上是 Subversion 的一個特性,稱為“peg-revisions”,Git 簡單地沒有對應的語法。因此,git svn
只是將 SVN 版本號新增到分支名稱中,就像您在 SVN 中編寫它來定址該分支的 peg-revision 一樣。如果您不再關心 peg-revisions,只需刪除它們:
$ for p in $(git for-each-ref --format='%(refname:short)' | grep @); do git branch -D $p; done
現在,所有舊分支都是真實的 Git 分支,所有舊標籤都是真實的 Git 標籤。
還有最後一件事要清理。不幸的是,git svn
建立了一個名為 trunk
的額外分支,它對映到 Subversion 的預設分支,但 trunk
引用指向與 master
相同的位置。由於 master
更符合 Git 的習慣用法,以下是刪除額外分支的方法:
$ git branch -d trunk
最後要做的是將您的新 Git 伺服器新增為遠端並推送到它。以下是將您的伺服器新增為遠端的示例:
$ git remote add origin git@my-git-server:myrepository.git
因為您希望所有分支和標籤都上傳,所以現在可以執行此命令:
$ git push origin --all
$ git push origin --tags
所有分支和標籤都應該以良好、乾淨的匯入方式存在於您的新 Git 伺服器上。
Mercurial
由於 Mercurial 和 Git 在表示版本方面有相當相似的模型,並且 Git 更加靈活,因此使用名為 "hg-fast-export" 的工具將倉庫從 Mercurial 轉換為 Git 是相當簡單的,您需要一份該工具的副本:
$ git clone https://github.com/frej/fast-export.git
轉換的第一步是完整克隆您要轉換的 Mercurial 倉庫:
$ hg clone <remote repo URL> /tmp/hg-repo
下一步是建立一個作者對映檔案。Mercurial 在變更集(changesets)的作者欄位中允許的內容比 Git 更寬鬆,所以這是一個清理的好時機。在 bash
shell 中生成它只需要一行命令:
$ cd /tmp/hg-repo
$ hg log | grep user: | sort | uniq | sed 's/user: *//' > ../authors
這需要幾秒鐘,具體取決於您專案的歷史記錄長度,之後 /tmp/authors
檔案將看起來像這樣:
bob
bob@localhost
bob <bob@company.com>
bob jones <bob <AT> company <DOT> com>
Bob Jones <bob@company.com>
Joe Smith <joe@company.com>
在此示例中,同一個人(Bob)以四個不同的名稱建立了變更集,其中一個實際上看起來是正確的,而另一個對於 Git 提交將完全無效。Hg-fast-export 允許我們透過將每行轉換為規則來解決此問題:"<input>"="<output>"
,將一個 <input>
對映到一個 <output>
。在 <input>
和 <output>
字串中,支援 Python string_escape
編碼理解的所有轉義序列。如果作者對映檔案不包含匹配的 <input>
,則該作者將未經修改地傳送到 Git。如果所有使用者名稱都看起來正常,我們根本不需要此檔案。在此示例中,我們希望檔案看起來像這樣:
"bob"="Bob Jones <bob@company.com>"
"bob@localhost"="Bob Jones <bob@company.com>"
"bob <bob@company.com>"="Bob Jones <bob@company.com>"
"bob jones <bob <AT> company <DOT> com>"="Bob Jones <bob@company.com>"
當 Git 不允許 Mercurial 名稱時,可以使用相同型別的對映檔案來重新命名分支和標籤。
下一步是建立我們的新 Git 倉庫,並執行匯出指令碼:
$ git init /tmp/converted
$ cd /tmp/converted
$ /tmp/fast-export/hg-fast-export.sh -r /tmp/hg-repo -A /tmp/authors
-r
標誌告訴 hg-fast-export 在哪裡找到我們要轉換的 Mercurial 倉庫,-A
標誌告訴它在哪裡找到作者對映檔案(分支和標籤對映檔案分別由 -B
和 -T
標誌指定)。該指令碼解析 Mercurial 變更集並將其轉換為 Git "fast-import" 功能的指令碼(我們稍後會詳細討論)。這需要一些時間(儘管它比透過網路快得多),並且輸出相當詳細:
$ /tmp/fast-export/hg-fast-export.sh -r /tmp/hg-repo -A /tmp/authors
Loaded 4 authors
master: Exporting full revision 1/22208 with 13/0/0 added/changed/removed files
master: Exporting simple delta revision 2/22208 with 1/1/0 added/changed/removed files
master: Exporting simple delta revision 3/22208 with 0/1/0 added/changed/removed files
[…]
master: Exporting simple delta revision 22206/22208 with 0/4/0 added/changed/removed files
master: Exporting simple delta revision 22207/22208 with 0/2/0 added/changed/removed files
master: Exporting thorough delta revision 22208/22208 with 3/213/0 added/changed/removed files
Exporting tag [0.4c] at [hg r9] [git :10]
Exporting tag [0.4d] at [hg r16] [git :17]
[…]
Exporting tag [3.1-rc] at [hg r21926] [git :21927]
Exporting tag [3.1] at [hg r21973] [git :21974]
Issued 22315 commands
git-fast-import statistics:
---------------------------------------------------------------------
Alloc'd objects: 120000
Total objects: 115032 ( 208171 duplicates )
blobs : 40504 ( 205320 duplicates 26117 deltas of 39602 attempts)
trees : 52320 ( 2851 duplicates 47467 deltas of 47599 attempts)
commits: 22208 ( 0 duplicates 0 deltas of 0 attempts)
tags : 0 ( 0 duplicates 0 deltas of 0 attempts)
Total branches: 109 ( 2 loads )
marks: 1048576 ( 22208 unique )
atoms: 1952
Memory total: 7860 KiB
pools: 2235 KiB
objects: 5625 KiB
---------------------------------------------------------------------
pack_report: getpagesize() = 4096
pack_report: core.packedGitWindowSize = 1073741824
pack_report: core.packedGitLimit = 8589934592
pack_report: pack_used_ctr = 90430
pack_report: pack_mmap_calls = 46771
pack_report: pack_open_windows = 1 / 1
pack_report: pack_mapped = 340852700 / 340852700
---------------------------------------------------------------------
$ git shortlog -sn
369 Bob Jones
365 Joe Smith
差不多就是這樣了。所有 Mercurial 標籤都已轉換為 Git 標籤,Mercurial 分支和書籤也已轉換為 Git 分支。現在,您可以將倉庫推送到其新的伺服器端位置:
$ git remote add origin git@my-git-server:myrepository.git
$ git push origin --all
Perforce
接下來要檢視的匯入系統是 Perforce。正如我們上面討論的,有兩種方法可以讓 Git 和 Perforce 相互通訊:git-p4 和 Perforce Git Fusion。
Perforce Git Fusion
Git Fusion 使此過程相當輕鬆。只需使用配置檔案(如 Git Fusion 中所討論的)配置您的專案設定、使用者對映和分支,然後克隆倉庫。Git Fusion 會為您留下一個看起來像原生 Git 倉庫的東西,如果您願意,可以隨時將其推送到原生 Git 主機。如果您喜歡,甚至可以使用 Perforce 作為您的 Git 主機。
Git-p4
Git-p4 也可以作為匯入工具。例如,我們將從 Perforce 公共倉庫匯入 Jam 專案。要設定您的客戶端,您必須匯出 P4PORT 環境變數以指向 Perforce 倉庫:
$ export P4PORT=public.perforce.com:1666
注意
|
為了繼續操作,您需要一個 Perforce 倉庫來連線。我們的示例將使用 public.perforce.com 上的公共倉庫,但您可以使用您有權訪問的任何倉庫。 |
執行 git p4 clone
命令,從 Perforce 伺服器匯入 Jam 專案,提供倉庫和專案路徑以及您要匯入專案的路徑:
$ git-p4 clone //guest/perforce_software/jam@all p4import
Importing from //guest/perforce_software/jam@all into p4import
Initialized empty Git repository in /private/tmp/p4import/.git/
Import destination: refs/remotes/p4/master
Importing revision 9957 (100%)
這個特定專案只有一個分支,但如果您有配置了分支檢視(或僅僅是一組目錄)的分支,您可以使用 git p4 clone
的 --detect-branches
標誌來匯入專案的所有分支。有關更多詳細資訊,請參閱 分支。
此時您幾乎完成了。如果您進入 p4import
目錄並執行 git log
,您可以看到您匯入的工作:
$ git log -2
commit e5da1c909e5db3036475419f6379f2c73710c4e6
Author: giles <giles@giles@perforce.com>
Date: Wed Feb 8 03:13:27 2012 -0800
Correction to line 355; change </UL> to </OL>.
[git-p4: depot-paths = "//public/jam/src/": change = 8068]
commit aa21359a0a135dda85c50a7f7cf249e4f7b8fd98
Author: kwirth <kwirth@perforce.com>
Date: Tue Jul 7 01:35:51 2009 -0800
Fix spelling error on Jam doc page (cummulative -> cumulative).
[git-p4: depot-paths = "//public/jam/src/": change = 7304]
您可以看到 git-p4
在每個提交訊息中都留下了一個識別符號。保留該識別符號是可以的,以防您以後需要引用 Perforce 變更號。但是,如果您想刪除該識別符號,那麼現在就是時候了——在您開始在新倉庫上工作之前。您可以使用 git filter-branch
大量刪除識別符號字串:
$ git filter-branch --msg-filter 'sed -e "/^\[git-p4:/d"'
Rewrite e5da1c909e5db3036475419f6379f2c73710c4e6 (125/125)
Ref 'refs/heads/master' was rewritten
如果您執行 git log
,您可以看到所有提交的 SHA-1 校驗和都已更改,但 git-p4
字串不再出現在提交訊息中:
$ git log -2
commit b17341801ed838d97f7800a54a6f9b95750839b7
Author: giles <giles@giles@perforce.com>
Date: Wed Feb 8 03:13:27 2012 -0800
Correction to line 355; change </UL> to </OL>.
commit 3e68c2e26cd89cb983eb52c024ecdfba1d6b3fff
Author: kwirth <kwirth@perforce.com>
Date: Tue Jul 7 01:35:51 2009 -0800
Fix spelling error on Jam doc page (cummulative -> cumulative).
您的匯入已準備好推送到您的新 Git 伺服器。
自定義匯入器
如果您的系統不是上述系統之一,您應該線上查詢匯入器——許多其他系統都有高質量的匯入器,包括 CVS、Clear Case、Visual Source Safe,甚至是一個存檔目錄。如果這些工具都不適合您,或者您有一個更不常見的工具,或者您需要更自定義的匯入過程,您應該使用 git fast-import
。此命令從標準輸入讀取簡單指令以寫入特定的 Git 資料。透過這種方式建立 Git 物件比執行原始 Git 命令或嘗試寫入原始物件(有關更多資訊,請參閱 Git 內部原理)容易得多。這樣,您可以編寫一個匯入指令碼,從您要匯入的系統中讀取必要的資訊,並向標準輸出列印簡單明瞭的指令。然後,您可以執行此程式並將其輸出透過管道傳遞給 git fast-import
。
為了快速演示,您將編寫一個簡單的匯入器。假設您在 current
中工作,您透過偶爾將目錄複製到帶時間戳的 back_YYYY_MM_DD
備份目錄來備份您的專案,並且您希望將其匯入到 Git 中。您的目錄結構看起來像這樣:
$ ls /opt/import_from
back_2014_01_02
back_2014_01_04
back_2014_01_14
back_2014_02_03
current
為了匯入 Git 目錄,您需要回顧 Git 如何儲存其資料。正如您可能記得的,Git 本質上是一個提交物件的連結串列,這些物件指向內容的快照。您所要做的就是告訴 fast-import
內容快照是什麼,哪些提交資料指向它們,以及它們的順序。您的策略是逐個遍歷快照,並使用每個目錄的內容建立提交,將每個提交連結回前一個提交。
正如我們在 Git 強制策略示例 中所做的那樣,我們將使用 Ruby 編寫此內容,因為這是我們通常使用的語言,並且它易於閱讀。您可以非常輕鬆地用您熟悉的任何語言編寫此示例——它只需要將適當的資訊列印到 stdout
。而且,如果您在 Windows 上執行,這意味著您需要特別注意不要在行尾引入回車符——git fast-import
對只要求換行符 (LF) 而不是 Windows 使用的回車換行符 (CRLF) 非常嚴格。
首先,您將進入目標目錄並識別每個子目錄,每個子目錄都是您想要作為提交匯入的快照。您將進入每個子目錄並列印匯出它所需的命令。您的基本主迴圈看起來像這樣:
last_mark = nil
# loop through the directories
Dir.chdir(ARGV[0]) do
Dir.glob("*").each do |dir|
next if File.file?(dir)
# move into the target directory
Dir.chdir(dir) do
last_mark = print_export(dir, last_mark)
end
end
end
您在每個目錄中執行 print_export
,它接受前一個快照的清單和標記,並返回當前快照的清單和標記;這樣,您就可以正確地連結它們。“標記”(Mark)是 fast-import
中用來標識提交的術語;在建立提交時,您會給每個提交一個標記,您可以使用該標記從其他提交連結到它。因此,您在 print_export
方法中要做的第一件事是根據目錄名稱生成一個標記:
mark = convert_dir_to_mark(dir)
您將透過建立一個目錄陣列並使用索引值作為標記來完成此操作,因為標記必須是整數。您的方法看起來像這樣:
$marks = []
def convert_dir_to_mark(dir)
if !$marks.include?(dir)
$marks << dir
end
($marks.index(dir) + 1).to_s
end
現在您有了提交的整數表示,您需要提交元資料的日期。由於日期是在目錄名稱中表達的,您將解析它。您的 print_export
檔案中的下一行是:
date = convert_dir_to_date(dir)
其中 convert_dir_to_date
定義為:
def convert_dir_to_date(dir)
if dir == 'current'
return Time.now().to_i
else
dir = dir.gsub('back_', '')
(year, month, day) = dir.split('_')
return Time.local(year, month, day).to_i
end
end
這會返回每個目錄日期的整數值。您為每個提交所需的最後一條元資訊是提交者資料,您將其硬編碼在全域性變數中:
$author = 'John Doe <john@example.com>'
現在您已準備好開始為您的匯入器列印提交資料。初始資訊宣告您正在定義一個提交物件及其所在的分支,然後是您生成的標記、提交者資訊和提交訊息,然後是前一個提交(如果有的話)。程式碼看起來像這樣:
# print the import information
puts 'commit refs/heads/master'
puts 'mark :' + mark
puts "committer #{$author} #{date} -0700"
export_data('imported from ' + dir)
puts 'from :' + last_mark if last_mark
您硬編碼時區 (-0700) 是因為這樣做很簡單。如果您從另一個系統匯入,則必須將時區指定為偏移量。提交訊息必須以特殊格式表達:
data (size)\n(contents)
格式由單詞 data、要讀取的資料大小、一個換行符以及最後的資料組成。由於您以後需要使用相同的格式來指定檔案內容,因此您建立了一個輔助方法 export_data
:
def export_data(string)
print "data #{string.size}\n#{string}"
end
剩下要做的就是為每個快照指定檔案內容。這很簡單,因為您將每個快照都放在一個目錄中——您可以列印 deleteall
命令,然後是目錄中每個檔案的內容。然後 Git 將適當地記錄每個快照:
puts 'deleteall'
Dir.glob("**/*").each do |file|
next if !File.file?(file)
inline_data(file)
end
注意:由於許多系統將其版本視為從一個提交到另一個提交的更改,因此 fast-import 也可以在每個提交中使用命令來指定哪些檔案已新增、刪除或修改以及新的內容是什麼。您可以計算快照之間的差異並僅提供這些資料,但這樣做更復雜——您不妨將所有資料提供給 Git,讓它自己計算出來。如果這更適合您的資料,請查閱 fast-import
手冊頁,瞭解如何以這種方式提供資料的詳細資訊。
列出新檔案內容或指定包含新內容的修改檔案的格式如下:
M 644 inline path/to/file
data (size)
(file contents)
這裡,644 是模式(如果您有可執行檔案,則需要檢測並指定 755),inline 表示您將在此行之後立即列出內容。您的 inline_data
方法看起來像這樣:
def inline_data(file, code = 'M', mode = '644')
content = File.read(file)
puts "#{code} #{mode} inline #{file}"
export_data(content)
end
您重用了之前定義的 export_data
方法,因為它與您指定提交訊息資料的方式相同。
您需要做的最後一件事是返回當前標記,以便將其傳遞給下一次迭代:
return mark
注意
|
如果您在 Windows 上執行,您需要確保新增一個額外的步驟。如前所述,Windows 使用 CRLF 作為換行符,而
|
就這樣。以下是完整的指令碼:
#!/usr/bin/env ruby
$stdout.binmode
$author = "John Doe <john@example.com>"
$marks = []
def convert_dir_to_mark(dir)
if !$marks.include?(dir)
$marks << dir
end
($marks.index(dir)+1).to_s
end
def convert_dir_to_date(dir)
if dir == 'current'
return Time.now().to_i
else
dir = dir.gsub('back_', '')
(year, month, day) = dir.split('_')
return Time.local(year, month, day).to_i
end
end
def export_data(string)
print "data #{string.size}\n#{string}"
end
def inline_data(file, code='M', mode='644')
content = File.read(file)
puts "#{code} #{mode} inline #{file}"
export_data(content)
end
def print_export(dir, last_mark)
date = convert_dir_to_date(dir)
mark = convert_dir_to_mark(dir)
puts 'commit refs/heads/master'
puts "mark :#{mark}"
puts "committer #{$author} #{date} -0700"
export_data("imported from #{dir}")
puts "from :#{last_mark}" if last_mark
puts 'deleteall'
Dir.glob("**/*").each do |file|
next if !File.file?(file)
inline_data(file)
end
mark
end
# Loop through the directories
last_mark = nil
Dir.chdir(ARGV[0]) do
Dir.glob("*").each do |dir|
next if File.file?(dir)
# move into the target directory
Dir.chdir(dir) do
last_mark = print_export(dir, last_mark)
end
end
end
如果您執行此指令碼,您將得到類似這樣的內容:
$ ruby import.rb /opt/import_from
commit refs/heads/master
mark :1
committer John Doe <john@example.com> 1388649600 -0700
data 29
imported from back_2014_01_02deleteall
M 644 inline README.md
data 28
# Hello
This is my readme.
commit refs/heads/master
mark :2
committer John Doe <john@example.com> 1388822400 -0700
data 29
imported from back_2014_01_04from :1
deleteall
M 644 inline main.rb
data 34
#!/bin/env ruby
puts "Hey there"
M 644 inline README.md
(...)
要執行匯入器,請在您要匯入到的 Git 目錄中,透過管道將此輸出傳遞給 git fast-import
。您可以建立一個新目錄,然後在其中執行 git init
作為起點,然後執行您的指令碼:
$ git init
Initialized empty Git repository in /opt/import_to/.git/
$ ruby import.rb /opt/import_from | git fast-import
git-fast-import statistics:
---------------------------------------------------------------------
Alloc'd objects: 5000
Total objects: 13 ( 6 duplicates )
blobs : 5 ( 4 duplicates 3 deltas of 5 attempts)
trees : 4 ( 1 duplicates 0 deltas of 4 attempts)
commits: 4 ( 1 duplicates 0 deltas of 0 attempts)
tags : 0 ( 0 duplicates 0 deltas of 0 attempts)
Total branches: 1 ( 1 loads )
marks: 1024 ( 5 unique )
atoms: 2
Memory total: 2344 KiB
pools: 2110 KiB
objects: 234 KiB
---------------------------------------------------------------------
pack_report: getpagesize() = 4096
pack_report: core.packedGitWindowSize = 1073741824
pack_report: core.packedGitLimit = 8589934592
pack_report: pack_used_ctr = 10
pack_report: pack_mmap_calls = 5
pack_report: pack_open_windows = 2 / 2
pack_report: pack_mapped = 1457 / 1457
---------------------------------------------------------------------
如您所見,當它成功完成時,它會為您提供有關其所完成工作的許多統計資訊。在這種情況下,您總共匯入了 13 個物件,對應 4 個提交,並匯入到 1 個分支中。現在,您可以執行 git log
檢視您的新歷史記錄:
$ git log -2
commit 3caa046d4aac682a55867132ccdfbe0d3fdee498
Author: John Doe <john@example.com>
Date: Tue Jul 29 19:39:04 2014 -0700
imported from current
commit 4afc2b945d0d3c8cd00556fbe2e8224569dc9def
Author: John Doe <john@example.com>
Date: Mon Feb 3 01:00:00 2014 -0700
imported from back_2014_02_03
好了——一個漂亮、乾淨的 Git 倉庫。需要注意的是,沒有任何檔案被檢出——一開始您的工作目錄中沒有任何檔案。要獲取它們,您必須將分支重置到 master
當前所在的位置:
$ ls
$ git reset --hard master
HEAD is now at 3caa046 imported from current
$ ls
README.md main.rb
您可以使用 fast-import
工具做更多事情——處理不同的模式、二進位制資料、多個分支和合並、標籤、進度指示器等等。Git 原始碼的 contrib/fast-import
目錄中提供了許多更復雜場景的示例。