![](/img/trans.png)
[英]How do I create a new git repository from a folder in an existing git repository?
[英]How do I create a “fresh new repository” in a directory where I already have a (messed up) the existing git repository?
將當前主分支的內容移至子分支的最佳方法是什么?
嘗試創建一個新的存儲庫,然后使用以下命令在.git / config中更改url-origin
git remote set-url origin git://new.url.here
您不能在現有的git存儲庫中創建另一個git存儲庫。
我在解釋我了解您的問題的方式。 我假設文件夾結構是:-
= Parent Directory
== Old Directory (git already initialized)
== New Directory (use git init to initialize git repository)
那里有一個包含子目錄的“父”目錄,而git在這些目錄下被初始化。 如果您以這種方式使用,那么它將起作用。
如果您想使用以下目錄結構
= Parent Directory == Old Directory (git already initialized) === New Directory (to initialize git repository with-in git repository, then it will not work)
在git中,如果要放棄本地更改,則不需要刪除並重新創建存儲庫。
只是做類似的事情
git checkout BRANCH_WITH_COMMITS_I_DONT_WANT
git reset --hard origin/BRANCH_WISH_COMMITS_I_DONT_WANT
請注意,這不是安全的工作目錄。請注意,您最終將丟失所有本地提交及其中包含的工作,但這聽起來像您要執行的操作。
在大多數情況下,重置分支比刪除和重新克隆要快得多。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.