![](/img/trans.png)
[英]Is it possible to move a bunch of files from one git repository to another while preserving (most) history?
[英]Move Git repository up 3 levels from current folder, preserving history and adding new files
我知道與此主題有很多類似的話題,但是我找不到我的情況的答案。 使用git 1.8.3.1我有一個git回購:
/path/to/my/git/repo/.git
我想將存儲庫移至/path/.git
同時保留原始存儲庫的歷史記錄+從新的根目錄添加新文件。 我嘗試將.git文件夾移動到適當的位置,重新添加所有文件並提交,但是我丟失了原始存儲庫的歷史記錄。
如何正確執行此操作? (過濾分支?)
謝謝
更新#1我的目的是將文件保留在原處,並擴展存儲庫以包括其父目錄+保留嵌套文件的歷史記錄:
舊倉庫:/ path / to / my / git / repo /
新倉庫:/ path /
更新#2我在想,也許有比這更簡單的解決方案,而不移動實際文件。
因此,這里基本上有兩個步驟:
A.移動git下的文件,以便git repo具有正確的根目錄:
cd /path/to/my/git/repo/
mkdir -p to/my/git/repo/
git mv * to/my/git/repo/
git status #check all files are moved.
git commit -m "megamove!!!"
B.將結果移到正確的位置:
mv * /path/
cd /path/
rm -r to/my/git/repo/ #drop empty dir
另外,另一種方法更簡單(但如果您的CRLF錯誤,有時可能會不太好用):
mv /path/to/my/git/repo/.git /path/
cd /path
git add -A
git status #check all files are moved.
git commit -m "megamove!!!"
歷史記錄應保留,使用git log -M
檢查
.git目錄包含您的Git存儲庫的元數據。 實際的Git回購很可能位於repo /下。
就您的操作系統而言,您的存儲庫只是一個目錄。 它可以移動到任何您想要的地方,Git存儲庫(包含歷史記錄)也將隨之移動。
因此,在您的示例中,您可能想要將repo /移至/ path:
mv /path/to/my/git/repo /path/.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.