0

I downloaded a github repository repo_A, made changes to it, initiated a new git repository repo_B and made some commits. Now I'm missing the git blame. There are many lines that point to my initial commit. So how do I merge the old commits from repo_A into repo_B without merging the commits made in repo_A after my initial commit?

I wouldn't expect any merge conflicts, but what I've tried so far has given me merge conflicts. And since repo_A has a long commit history, it would take me too long to fix all the merge conflicts.

I've found a way to do this the other way around: How to copy commits from one Git repo to another?

git clone https://github.com/path/to/repo_A repo_A
cd repo_A   
git reset --hard old_commit
git fetch /path/to/repo_B

# examine the whole tree
git log --all --oneline --graph --decorate

# copy (cherry-pick) the commits from repo_B into your new repo_A
git cherry-pick sha-first-commit-from-repo_B^ sha-last-commit-from-repo_B

But I don't see the commits from repo_B anywhere.

# check your local repo is correct
git log

# send your new tree (repo state) to github
git push origin main

# remove the now-unneeded reference to repo_B
git remote remove repo_B
  • You can cherry pick a whole range of commits in one command. – matt Jan 21 '22 at 17:25
  • Oh you are right `first^..last` but still, I think there are some other commits that I haven't reset because of the branches or something. I still can't merge the commits. –  Jan 21 '22 at 17:42

0 Answers0