0

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.

Stack Undefined
  • 1,050
  • 1
  • 14
  • 23
  • 1
    Does this answer your question? [How do you merge two Git repositories?](https://stackoverflow.com/questions/1425892/how-do-you-merge-two-git-repositories) – Adrian J. Moreno May 14 '21 at 20:41
  • @AdrianJ.Moreno Thanks for the link. I tried few suggested answers but was getting errors and don't have time. So I ended up copying the folder and pasting into RepoB. – Stack Undefined May 14 '21 at 21:31
  • Does this answer your question? [git move directory to another repository while keeping the history](https://stackoverflow.com/questions/41811986/git-move-directory-to-another-repository-while-keeping-the-history) – Hugh Perkins Nov 29 '21 at 14:58

1 Answers1

2

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.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Thanks for the explanation. I ended up just doing the good old copy/paste and called it a day. I've been running into lots of issues and don't have time unfortunately. May be I will go through some of the suggested SO answers when I have time. Plus the the commit history in the POC project is not that important if I lose it. I'm used to Visual Studio and TortoiseGit GUI tools for git but time to time I find myself on the git cli dark side. – Stack Undefined May 14 '21 at 21:20