git 如何在没有整个历史的情况下克隆种子/启动项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29748197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to clone seed/kick-start project without the whole history?
提问by itamar
Note that using --depth=1
parameter prevents you from pushing the project to a new repository.
请注意,使用--depth=1
参数可防止您将项目推送到新存储库。
for details see: "Remote rejected" (shallow update not allowed) after changing Git remote URL
有关详细信息,请参阅:更改 Git 远程 URL 后的“远程拒绝”(不允许浅更新)
回答by Ajay
You can do a
你可以做一个
git clone <git_url>
delete the .git repository from your folder. Which will delete all your history.
从您的文件夹中删除 .git 存储库。这将删除您的所有历史记录。
The you can do a
你可以做一个
git init
which will create an entirely new git project for you.
这将为您创建一个全新的 git 项目。
This may not be the best way. But this will work . Hope it helps.
这可能不是最好的方法。但这会奏效。希望能帮助到你。
回答by Sascha Wolf
As long as you consider full loss of history to be no issue, the approach suggested by Ajay is perfectly valid. But in case you want to maintain the history of your shallow clone I have a different suggestion.
只要您认为完全丢失历史记录没有问题,Ajay 建议的方法就完全有效。但是,如果您想保留浅层克隆的历史记录,我有一个不同的建议。
A shallow clone pretends to have the full history by using a so called graft pointto fake the parent of the "first" commit. If we assume that we have the full history available, we could rephrase the question: How can I throw away the history before a specific revision?
浅层克隆通过使用所谓的嫁接点来伪造“第一次”提交的父级,从而假装拥有完整的历史记录。如果我们假设我们有完整的历史可用,我们可以重新表述这个问题:在特定修订之前我如何丢弃历史?
This means we can use a combination of a graft point and git filter-branch
(as suggested in the linked question). However you have to note that this will rewrite your full history, making the new one incompatible with the remote we initially cloned from. Due to this, we should remove the old remote from our repository.
这意味着我们可以使用嫁接点和git filter-branch
(如链接问题中所建议的)的组合。但是您必须注意,这将重写您的完整历史记录,使新的历史记录与我们最初克隆的遥控器不兼容。因此,我们应该从我们的存储库中删除旧的遥控器。
git remote remove <old-remote-name>
Now we can start our rewrite. Let's assume that we want to make current mastercommit the new root for the repository.
现在我们可以开始我们的重写了。让我们假设我们想让当前的master提交存储库的新根。
git rev-parse --verify master >> .git/info/grafts
git filter-branch -- --all
This will rewrite the full history of our repository, with the current master commit as the new root. You can finalize the rewrite by removing the "backup" references in refs/original
. Furthermore you can now delete the .git/shallow
file.
这将重写我们存储库的完整历史记录,将当前的主提交作为新的根。您可以通过删除refs/original
. 此外,您现在可以删除该.git/shallow
文件。
After you've done this, you should be able to push the now ungraftedhistory in your new remote.
完成此操作后,您应该能够在新遥控器中推送现在未嫁接的历史记录。
回答by Aleksander Alekseev
Try something like this:
尝试这样的事情:
mkdir -p /tmp/git-copy
cd /tmp/git-copy
# create another copy of your repository
git clone file:///path/to/cloned/repo
cd repo
git rebase -i (first-commit)
# in vim:
# :2,$s/^pick/squash
# :w
# Now wait, it will take a while...
git push --mirror [email protected]:username/new-repo.git
I tried it just now on this repository. Seems to work - no history and all submodules are intact.
我刚刚在这个存储库上尝试过。似乎有效 - 没有历史记录,所有子模块都完好无损。