简体   繁体   English

将所有git commit作为一个推送,以清空裸仓库

[英]Push all git commits as one to empty bare repo

I have two bare repositories. 我有两个裸仓库。

repo1 - with all the history repo1具有所有历史
repo2 - new, empty one repo2新的,空的

I want to push all the files from repo1 to repo2 , but without the whole history, just the the state from the last commit. 我想将所有文件从repo1推送到repo2 ,但是没有整个历史记录,只是最后一次提交的状态。

I don't want to touch the history of the repo1 (it's best to assume it's read only). 我不想触碰repo1的历史(最好假设它是只读的)。 In the new repo I don't want to have any history (including reflogs), so shashing after the push is not an option. 在新的仓库中,我不希望有任何历史记录(包括reflog),因此在推送后进行shashing是不可行的。

Is this ever possible without creating new, temporary repository? 如果不创建新的临时存储库,是否有可能?
How can I achieve this? 我该如何实现?

Do the following: 请执行下列操作:

git checkout --orphan temp_branch
git commit -m "initial commit"
git push repo2 temp_branch:master

This will create a temp_branch locally with just a single commit with the current snapshot, and push it to a branch called "master" on repo2. 这将在本地创建temp_branch,只需对当前快照进行一次提交,并将其推送到repo2上名为“ master”的分支。

Assuming that you want to clone the head of master and assuming that you do not insist on a git push : 假设您想克隆master的负责人,并假设您不坚持git push

# in repo2
# git fetch --depth 1 path_to_repo1 master:master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM