2017-02-12 163 views
-1

我有一個Git倉庫,其具有n個承諾,我想創造一些特別米的新倉庫提交,Git倉庫提交

例, 資源庫中有10個提交,並從第4犯我要創建一個新的庫B的獨立A的

我試過許多東西,但他們沒有工作像 混帳克隆,然後在新目錄中的git結算和多堆棧溢出的答案,

How do I create a new git repository from a folder in an existing git repository?

how to create a new git repository from an existing one

但是無法在提交方面執行它。任何人都可以請幫忙。

感謝

+0

你的意思是,你想創建新的根提交與其他提交相同的內容? – PetSerAl

+0

問題需要澄清。製作示例圖可以提供很多幫助。 – LopSae

回答

0

克隆回購A. 打開遙控「出身」,如果你想它的獨立。 然後(學習如何和)使用git rebase -i來選擇提交保留,刪除或擠壓。 如果你只有10個提交,並且你想刪除的提交沒有後來提交的發生,它應該很好...

0

因爲它通常與git,有很多方法皮貓:)

上述答案另一種方法是添加一個空倉庫爲遠程和推提交使用git push other_remote commit:refs/heads/master

這裏有一個演示:

# Set up the parent repo 
$ git init repo1 
Initialized empty Git repository in /tmp/repo1/.git/ 
$ cd repo1 
$ seq 10 | xargs --replace git commit -m 'commit {}' --allow-empty 
[master (root-commit) 7444793] commit 1 
[master 6b12c35] commit 2 
[master 3743f03] commit 3 
[master b4221a7] commit 4 
[master f7e1009] commit 5 
[master 4c8e4e9] commit 6 
[master 6618f10] commit 7 
[master a1c1b26] commit 8 
[master 802bed2] commit 9 
[master 13734f2] commit 10 
# Set up the new repo 
git init ../repo2 
# Allow pushing to the master branch 
git -C ../repo2 config receive.denyCurrentBranch ignore 
# Add the other repo as a remote 
git remote add other_remote ../repo2 
# Push the commit 5-back to repo2's master branch 
# Note you can use anything that resolves to a refish like thing (a branch, a commit, a tag, etc.) 
git push other_remote HEAD^^^^^:refs/heads/master 
# Show our handywork 
$ cd ../repo2 
$ git log --oneline 
f7e1009 commit 5 
b4221a7 commit 4 
3743f03 commit 3 
6b12c35 commit 2 
7444793 commit 1 
0

比方說,提交歷史Ø在回購A中的f masterA-B-C-D-E。目標是創建一個分支指向C的回購B.

git init RepoB 
cd RepoB 
git fetch <path_of_RepoA> master 
git checkout -b master C