简体   繁体   English

如何将文件及其所有提交历史记录迁移到git中的新仓库中?

[英]How to migrate a file and all its commit history to a new repo in git?

I have a repo (repoA) and a file in that repo has 20-30 commits; 我有一个仓库(repoA),该仓库中的文件有20-30次提交; I want to move that file to repoB with all of the commit history; 我想将该文件与所有提交历史记录一起移到repoB; how do I do that? 我怎么做?

If what you want to move is the whole branch as it is, just add a new remote pointing to the new repo and push the branch to it. 如果要移动的是整个分支,则只需添加指向新仓库的新远程对象,然后将分支推入该分支即可。 If you have 30 commits with say 50 files and you want to move the history of a "single" file, as if the file was always alone you will have to rewrite the history of the branch so that you get only the history of that file, no more and then you will add the remote and then push to it. 如果您有30个提交(例如50个文件),并且想要移动“单个”文件的历史记录,就好像该文件始终是单独的一样,则您将不得不重写分支的历史记录,以便仅获取该文件的历史记录,再也没有了,然后您将添加遥控器,然后将其推入。

https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History

As I understand you want to move changes only from one file and save the history of all repository. 据我了解,您只想移动一个文件中的更改并保存所有存储库的历史记录。

Commits in git aren't about some file. git中的提交与某些文件无关。 They are about repository. 它们是关于存储库的。

Maybe you can do something like: 也许您可以执行以下操作:

1)get file changes from repoA and copy them in repoB as new commit. 1)从repoA获取文件更改,并将其作为新提交复制到repoB中。

2)after some time push repoB into master for example 2)例如一段时间后将repoB推入master

3)merge master with repoA. 3)将主服务器与repoA合并。 Resolve conflicts if any. 解决冲突(如果有)。

暂无
暂无

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

相关问题 如何在不丢失所有提交历史记录的情况下将仓库迁移到git-lfs? - How to migrate a repo to git-lfs without losing all the commit history? 如何将具有历史记录的SVN存储库的一部分迁移到新的Git存储库? - How to migrate part of an SVN repo with history to a new Git repository? 如何回滚 Git 存储库以首先提交并删除所有历史记录 - How to roll back Git repo to first commit and delete all history 如何完全迁移具有历史记录的 git repo? - How to fully migrate a git repo with with history? git 历史消失了 - 如何在创建新项目后将旧的 git repo 迁移到新的 - git history gone - How to migrate older git repo to the new one after creating new project 如果旧的存储库不在线,如何将所有提交历史记录保存在旧的存储库中,并将其内容移动到新的存储库中? - How to keep all commit history in an old repo and move its content into a new one if the old repository doesn't exist online? 将Git repo克隆到新的repo中 - 没有提交历史记录 - Cloning a Git repo into a new repo - without commit history 将目录从一个Git存储库迁移到具有所有历史记录的另一个目录 - Migrate a directory from one Git repo to another with ALL history 如何创建一个新的 git 回购,其第一次提交是源的最后一次提交(没有历史,没有链接到源回购,只有主分支) - how create a new git repo whose first commit is the last commit of the source (no history, not linked to source repo, and only the master branch) 如何将 git 存储库合并到维护提交历史记录的父存储库中? - How to merge a git repo into a parent repo maintaining commit history?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM