简体   繁体   English

将一个 git 存储库复制到另一个具有历史记录的存储库

[英]Copying one git repo to another repo with history

How to copy one repo entirely to another repo with history.如何将一个存储库完全复制到另一个具有历史记录的存储库。

I don't want to use fork or mirroring options, I tried out branch-filter options but it is limited to one directory.我不想使用 fork 或镜像选项,我尝试了分支过滤器选项,但它仅限于一个目录。 git filter-branch --subdirectory-filter /../RepoA/dire1 git filter-branch --subdirectory-filter /../RepoA/dire1

I was referring below url https://medium.com/@ayushya/move-directory-from-one-repository-to-another-preserving-git-history-d210fa049d4b/我指的是下面 url https://medium.com/@ayushya/move-directory-from-one-repository-to-another-preserving-git-history-d210fa049d4b/

Example:
Source      Target             Requirement
------      ----              -------------------
RepoA       RepoB(new Repo)   Copy entire history  
  - Dir1     - Dir1
  - Dir2     - Dir2

Could you please suggest?你能建议吗?

You can try using the --index-filter instead of the --subdirectory-filter .您可以尝试使用--index-filter而不是--subdirectory-filter

$ git filter-branch --index-filter \
    'git ls-files -s | sed "s#\t#&RepoA/#" |
     GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
     git update-index --index-info &&
     mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD

Please checkout this thread for more information.请查看此线程以获取更多信息。

If RepoB is a fresh new repo.如果 RepoB 是一个全新的 repo。 Yon can also try below commands. Yon 也可以尝试以下命令。 Clone RepoA to local machine, remove the remote origin of RepoA, then add the remote url to RepoB.将 RepoA 克隆到本地机器,删除 RepoA 的远程源,然后将远程 url 添加到 RepoB。 see below example:见下面的例子:

git clone http:/url/repoA
cd repoA
git pull origin branchName
git remote remove origin
git remote add origin http:/url/repoB
git push -u origin --all

You can also try using git submodule.您也可以尝试使用 git 子模块。 Check the git document for more information.查看git 文档了解更多信息。

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

相关问题 如何将一个 repo 移动到另一个 repo 文件夹并保留 git 历史记录? - How to move one repo to another repo folder and keep git history? 将一个回购合并到另一个回购的历史中 - Merging One Repo Into Another Repo's History 将合并的请求请求从一个Git存储库复制到另一个 - Copying merged pull requests from one Git repo to another 将目录从一个Git存储库迁移到具有所有历史记录的另一个目录 - Migrate a directory from one Git repo to another with ALL history 将资产从一个仓库移到另一个仓库,git提交历史? - Moving Assets from one Repo to another, git commit history? 将子文件夹从一个 git repo 移动到另一个保留历史记录 - Moving subfolder from one git repo to another preserving history 如何在 git 中将一个仓库转移到另一个仓库 - How to transfer one repo to another repo in git 将文件夹从一个存储库复制/移动到另一个存储库,同时保留 Git 中的历史记录 - Copy/Move a folder from one repo to another repo while preserving history in Git 将 git 存储库与另一个存储库的子目录合并,保持历史记录 - Merge git repo with another repo's subdirectory, maintaining history GIT 将一个仓库与另一个仓库中的文件夹合并,而不会丢失历史记录 - GIT MERGE a repo with a folder in another repo without loosing history
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM