-
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
,以協助它更準確地對應作者資料。您也可以透過將 --no-metadata
傳遞給 clone
或 init
命令來告知 git svn
不包含 Subversion 通常匯入的 metadata。 metadata 包括 Git 在匯入期間會在每個提交訊息中產生一個 git-svn-id
。這可能會膨脹您的 Git 日誌,並使其變得有些不明確。
注意
|
當您想要將 Git 儲存庫中的 commit 鏡像回原始的 SVN 儲存庫時,需要保留 metadata。如果您不希望 commit log 中有同步資訊,可以省略 |
這會讓您的 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 import。而不是看起來像這樣的 commit
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
不僅 Author 欄位看起來好很多,連 git-svn-id
也消失了。
您還應該做一些 import 後的清理工作。首先,您應該清理 git svn
設定的一些奇怪的 references。首先,您將移動 tags,讓它們成為真正的 tags,而不是奇怪的遠端分支,然後您將移動其餘的分支,讓它們成為本地分支。
要將 tags 移動成為正確的 Git tags,請執行
$ 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/
開頭的遠端分支 references 轉換為真正的(輕量級)tags。
接下來,將 refs/remotes
下的其他 references 移動為本地分支
$ 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 分支,所有舊的 tags 都是真正的 Git tags。
還有一件事要清理。不幸的是,git svn
會建立一個名為 trunk
的額外分支,它會對應到 Subversion 的預設分支,但 trunk
ref 指向的位置與 master
相同。由於 master
更符合 Git 的慣例,以下是如何移除額外分支的方法
$ git branch -d trunk
最後要做的是將您新的 Git 伺服器新增為 remote 並推送上去。以下是如何將您的伺服器新增為 remote 的範例
$ git remote add origin git@my-git-server:myrepository.git
因為您希望所有分支和 tags 都推送上去,所以現在可以執行這個指令
$ git push origin --all
$ git push origin --tags
您所有的分支和 tags 都應該以一個乾淨的 import 方式在您新的 Git 伺服器上。
Mercurial
由於 Mercurial 和 Git 在表示版本的方式上相當相似,而且 Git 更為靈活,因此使用一個名為 "hg-fast-export" 的工具將儲存庫從 Mercurial 轉換為 Git 是相當簡單的,您需要一份這個工具的副本
$ git clone https://github.com/frej/fast-export.git
轉換的第一步是取得您要轉換的 Mercurial 儲存庫的完整 clone
$ hg clone <remote repo URL> /tmp/hg-repo
下一步是建立一個 author mapping 檔案。Mercurial 在 changeset 的 author 欄位中會比 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)使用四個不同的名稱建立了 changeset,其中一個看起來是正確的,而另一個對 Git commit 來說是完全無效的。Hg-fast-export 讓我們可以透過將每一行轉換成一個規則來修正這個問題:"<input>"="<output>"
,將 <input>
對應到 <output>
。在 <input>
和 <output>
字串中,支援 Python string_escape
編碼所理解的所有 escape sequences。如果 author mapping 檔案沒有包含符合的 <input>
,則該 author 將會以未修改的方式傳送到 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>"
當 Mercurial 名稱不被 Git 允許時,可以使用相同類型的 mapping 檔案來重新命名分支和 tag。
下一步是建立我們新的 Git 儲存庫,並執行 export 指令
$ 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
標誌告訴它在哪裡找到 author-mapping 檔案(分支和 tag mapping 檔案分別由 -B
和 -T
標誌指定)。該指令會解析 Mercurial changeset 並將它們轉換為 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 tag 都已轉換為 Git tag,而 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 中所述)設定您的專案設定、使用者 mapping 和分支,然後 clone 儲存庫即可。Git Fusion 會讓您擁有一個看起來像是原生 Git 儲存庫的東西,然後您可以將它推送到原生的 Git 主機。如果您願意,甚至可以使用 Perforce 作為您的 Git 主機。
Git-p4
Git-p4 也可以作為匯入工具。舉例來說,我們將從 Perforce Public Depot 匯入 Jam 專案。要設定您的用戶端,您必須匯出 P4PORT 環境變數以指向 Perforce depot
$ export P4PORT=public.perforce.com:1666
注意
|
為了跟著範例操作,您需要一個 Perforce depot 來連線。我們的範例將使用 public.perforce.com 的 public depot,但您可以使用您有權限存取的任何 depot。 |
執行 git p4 clone
指令從 Perforce 伺服器匯入 Jam 專案,提供 depot 和專案路徑以及您想要匯入專案的路徑
$ 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
在每個 commit message 中都留下了一個識別符。如果您以後需要參考 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
,您可以看到 commit 的所有 SHA-1 校驗和都已變更,但 commit message 中不再有 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
。此指令從 stdin 讀取簡單的指令,以寫入特定的 Git 資料。以這種方式建立 Git 物件比執行原始 Git 指令或嘗試寫入原始物件容易得多(有關更多資訊,請參閱Git 內部)。透過這種方式,您可以編寫一個匯入指令碼,從您要匯入的系統中讀取必要資訊,並將簡單的指令列印到 stdout。然後,您可以執行此程式並將其輸出透過 pipe 傳輸到 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 基本上是一個 commit 物件的連結清單,這些物件指向內容的快照。您所要做的就是告訴 fast-import
內容快照是什麼,哪些 commit 資料指向它們,以及它們的順序。您的策略是一次查看一個快照,並使用每個目錄的內容建立 commit,將每個 commit 連回上一個 commit。
正如我們在一個範例 Git 強制政策中所做的那樣,我們將用 Ruby 編寫這個,因為它通常是我們使用的,而且往往易於閱讀。您可以用您熟悉的任何語言輕鬆地編寫這個範例 - 它只需要將適當的資訊列印到 stdout
。而且,如果您在 Windows 上執行,這表示您需要特別注意不要在行的末尾引入歸位字元 - git fast-import
非常挑剔,只想要換行符號 (LF),而不是 Windows 使用的歸位換行符號 (CRLF)。
首先,您將變更到目標目錄,並識別每個子目錄,每個子目錄都是您想要匯入為 commit 的快照。您將變更到每個子目錄,並列印匯出它所需的指令。您的基本主迴圈如下所示
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
---------------------------------------------------------------------
如您所見,當它成功完成時,它會提供一些關於它完成事項的統計資訊。在本例中,您總共為 1 個分支中的 4 個提交匯入了 13 個物件。現在,您可以執行 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
目錄中提供了許多更複雜情境的範例。