简体   繁体   中英

Copy/Move a folder from one repo to another repo while preserving history in Git

I have a new git repo RepoA with a proof of concept project in my laptop that isn't stored anywhere else and another repo RepoB I checked out from Azure DevOps. I just want to copy the entire project in RepoA into a folder in RepoB while preserving the history of the project from RepoA . So the history for RepoB will display all the history entries for RepoA along with RepoB 's history. Is this possible?

How can I do this in few steps (as opposed a mile long list of git cli commands in many SO answers). I don't want to filter anything in RepoA , just copy the root folder into RepoB with all the history intact.

History, in a Git repository, is nothing more or less than the commits in the Git repository.

No commit can ever be changed. You can, however, throw out some old set of commits in favor of some new-and-improved set of commits. You can, at any time, add new commits, either by literally just adding commits, one at a time, or by using git merge to combine some old chain of commits with some other old chain of commits. The latter works because git log finds commits by working backwards, one commit at a time, from more-recent commits to older commits; upon reaching a merge commit, git log follows both chains unless instructed to follow only one chain .

How git log follows both chains, or only one chain, and the way you instruct it to do one or the other, can get very complicated. That may affect how you choose to go about adding your commits.

Other than that, though, you either use a cheap and dirty merge (with --allow-unrelated-histories if needed) to whack the two repositories' commits into one messy mass, or you use the other SO answers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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